1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/apisupport/release/nb-prof-debug/time-delta.pl Sun Mar 21 09:57:30 2004 +0000
1.3 @@ -0,0 +1,119 @@
1.4 +#!/usr/bin/perl -w
1.5 +# Sun Public License Notice
1.6 +#
1.7 +# The contents of this file are subject to the Sun Public License
1.8 +# Version 1.0 (the "License"). You may not use this file except in
1.9 +# compliance with the License. A copy of the License is available at
1.10 +# http://www.sun.com/
1.11 +#
1.12 +# The Original Code is NetBeans. The Initial Developer of the Original
1.13 +# Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun
1.14 +# Microsystems, Inc. All Rights Reserved.
1.15 +
1.16 +use strict;
1.17 +use File::Basename qw(dirname);
1.18 +# If you don't have this, get it from CPAN:
1.19 +use Time::HiRes qw(time);
1.20 +
1.21 +unless (@ARGV) {
1.22 + print STDERR <<'USAGE';
1.23 +Measure startup-time impact of a change to NetBeans.
1.24 +
1.25 +Usage: time-delta.pl RUNIDE_OLD.SH RUNIDE_NEW.SH ARG...
1.26 +
1.27 +Suggested flags (in ARG section):
1.28 +-nogui -nosplash Run in non-GUI mode
1.29 +-J-Dnetbeans.warm.close=true Run warm-up tasks before exiting
1.30 +
1.31 +Implied flags (always included):
1.32 +
1.33 +-userdir <<testarea>> -J-Dnetbeans.logger.console=false -J-Dnetbeans.close=true -J-Dnetbeans.full.hack=true
1.34 +
1.35 +This script (and the NB build in it) should maybe be in /dev/shm or a
1.36 +similar RAM disk. Disable as many other apps on the machine as possible,
1.37 +or timing results may be disturbed.
1.38 +USAGE
1.39 + exit 2;
1.40 +}
1.41 +my $runide_old = shift;
1.42 +my $runide_new = shift;
1.43 +print "Testing startup time in: $runide_old and $runide_new\n";
1.44 +print "Shut down any other major running GUI apps before starting!\n";
1.45 +print "That includes fancy screensavers.\n";
1.46 +print "Now go get some coffee and come back in ten minutes.\n";
1.47 +
1.48 +my $primer_stages = 3;
1.49 +my $real_stages = 15;
1.50 +my $userdir_base = -w "/dev/shm" ? "/dev/shm/time-delta-ud" : "/tmp/time-delta-ud";
1.51 +system('rm', '-rfv', $userdir_base) and die "rm -rfv $userdir_base: $!";
1.52 +
1.53 +sub run($$) {
1.54 + my ($stage, $opt) = @_;
1.55 + if ($opt eq 'true') {
1.56 + print "Running optimized $stage...\n";
1.57 + } else {
1.58 + print "Running unoptimized $stage...\n";
1.59 + }
1.60 + my $actual_userdir = "$userdir_base/opt-$opt";
1.61 + unlink("$actual_userdir/system/ide.log"); # OK if fails
1.62 + my $start = time;
1.63 + my $actual_runide = ($opt eq 'true') ? $runide_new : $runide_old;
1.64 + system($actual_runide, '-userdir', $actual_userdir, '-J-Dnetbeans.logger.console=false', '-J-Dnetbeans.close=true', '-J-Dnetbeans.full.hack=true', @ARGV)
1.65 + and die "Failed to start NetBeans: $!";
1.66 + my $end = time;
1.67 + my $delta = $end - $start;
1.68 + print "\tElapsed time: $delta\n";
1.69 + return $delta;
1.70 +}
1.71 +
1.72 +# Run primer stages to get RAM and disk cache ready:
1.73 +foreach my $i (map {"primer$_"} 1..$primer_stages) {
1.74 + foreach my $j ('false', 'true') {
1.75 + run($i, $j);
1.76 + }
1.77 +}
1.78 +
1.79 +# Now the real runs:
1.80 +my $unopted = 0;
1.81 +my @unopted = ();
1.82 +my $opted = 0;
1.83 +my @opted = ();
1.84 +foreach my $i (map {"stage$_"} 1..$real_stages) {
1.85 + my $time = run($i, 'false');
1.86 + push @unopted, $time;
1.87 + $unopted += $time;
1.88 + $time = run($i, 'true');
1.89 + push @opted, $time;
1.90 + $opted += $time;
1.91 +}
1.92 +
1.93 +# Lies, damn lies, and statistics:
1.94 +$unopted /= $real_stages;
1.95 +$opted /= $real_stages;
1.96 +my $delta = $unopted - $opted;
1.97 +my $perc = $delta / $unopted * 100;
1.98 +my $unopted_sumsq = 0;
1.99 +foreach my $i (@unopted) {$unopted_sumsq += ($i - $unopted) ** 2}
1.100 +my $unopted_stddev = sqrt($unopted_sumsq / ($real_stages - 1));
1.101 +my $opted_sumsq = 0;
1.102 +foreach my $i (@opted) {$opted_sumsq += ($i - $opted) ** 2}
1.103 +my $opted_stddev = sqrt($opted_sumsq / ($real_stages - 1));
1.104 +print "Average times: unoptimized $unopted\n";
1.105 +print " std. dev. $unopted_stddev\n";
1.106 +print " optimized $opted\n";
1.107 +print " std. dev. $opted_stddev\n";
1.108 +print "Improvement: $delta\n";
1.109 +print "Percentage: $perc%\n";
1.110 +my $max_dev = ($unopted_stddev > $opted_stddev) ? $unopted_stddev : $opted_stddev;
1.111 +print "Executive summary:\n";
1.112 +if ($delta < 0) {
1.113 + print "You're a hoser.\n";
1.114 +} elsif ($delta < $max_dev) {
1.115 + print "These numbers are so close as to be meaningless. Give up.\n";
1.116 +} elsif ($delta < 2 * $max_dev) {
1.117 + print "You might have saved a little time, but it's not really clear.\n";
1.118 +} elsif ($delta < 3 * $max_dev) {
1.119 + print "You probably saved some time here, though it is not for sure.\n";
1.120 +} else {
1.121 + print "You pretty clearly saved time. Congratulations!\n";
1.122 +}