|
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
|
Re: What use is the Schwartzian Transform?
|
> I got a much larger differential than 5%; see below.
Something is obviously wrong with your benchmarks. To start with,
they claim that on your computer, Perl can sort 9952 items in 3.85
microseconds flat. I find that impossible to believe.
Moreover:
> 'CODE A' => '@sorted = sort { -M $b <=> -M $a } @filenames;',
This code is supposed to be sorting a list of 9952 filenames. You
can't do that with fewer than 9951 calls to the comparator, and
therefore with fewer than 19,902 -M operations. For a typical set of
random data, the comparator is called 120214 times (put '$count++'
into the comparator to see this) therefore making 240428 -M
operations.
Now, according to your benchmark,
> CODE A: 39 wallclock secs
> (38.50 usr + 0.00 sys = 38.50 CPU) @ 259740.26/s (n000000)
the system has taken 0.00 seconds to perform these 19,902 -M's, or
maybe it is more like 240428 -M's.
That's bullshit.
> Note further that, as you predicted, Code D was fractionally faster than
> Code B. However, contrary to your prediction, Code B was more than
> twice as fast as Code C -- not just 5% faster.
No credit or blame attaches to me for predicting or failing to predict
the results of your absurd benchmarks.
Here's the code I used; the array had 125 entries.
$IT = shift || 1000;
opendir D, "/tmp" or die;
@files = map "/tmp/$_", readdir D;
closedir D;
print "NULL LOOP\n";
my ($u1, $s1) = times();
my $t1 = $u1 + $s1;
for (1..$IT) {
1;
}
my ($u2, $s2) = times();
my $t2 = $u2 + $s2;
my ($ue, $se, $te) = ($u2-$u1, $s2-$s1, $t2-$t1);
printf "Elapsed: %6.2fu %6.2fs %6.2ftotal\n", $ue, $se, $te;
print "ST\n";
my ($u1, $s1) = times();
my $t1 = $u1 + $s1;
for (1..$IT) {
my @sorted = map {$_->[0]} sort { $b->[1] <=> $a->[1] }
map { [$_, -M $_] } @files;
}
my ($u2, $s2) = times();
my $t2 = $u2 + $s2;
my ($ue, $se, $te) = ($u2-$u1, $s2-$s1, $t2-$t1);
printf "Elapsed: %6.2fu %6.2fs %6.2ftotal\n", $ue, $se, $te;
print "ST (noblock)\n";
my ($u1, $s1) = times();
my $t1 = $u1 + $s1;
for (1..$IT) {
my @sorted = map $_->[0], sort { $b->[1] <=> $a->[1] }
map [$_, -M $_], @files;
}
my ($u2, $s2) = times();
my $t2 = $u2 + $s2;
my ($ue, $se, $te) = ($u2-$u1, $s2-$s1, $t2-$t1);
printf "Elapsed: %6.2fu %6.2fs %6.2ftotal\n", $ue, $se, $te;
print "ST (hash)\n";
my ($u1, $s1) = times();
my $t1 = $u1 + $s1;
for (1..$IT) {
my @sorted = map {$_->{name}} sort { $b->{date} <=> $a->{date} }
map { {name => $_, date => -M $_} } @files;
}
my ($u2, $s2) = times();
my $t2 = $u2 + $s2;
my ($ue, $se, $te) = ($u2-$u1, $s2-$s1, $t2-$t1);
printf "Elapsed: %6.2fu %6.2fs %6.2ftotal\n", $ue, $se, $te;
print "Aux. hash\n";
my ($u1, $s1) = times();
my $t1 = $u1 + $s1;
for (1..$IT) {
my %date;
$date{$_} = -M $_ for @files;
my @sorted = sort {$date{$b} <=> $date{$a}} @files;
undef %date;
}
my ($u2, $s2) = times();
my $t2 = $u2 + $s2;
my ($ue, $se, $te) = ($u2-$u1, $s2-$s1, $t2-$t1);
printf "Elapsed: %6.2fu %6.2fs %6.2ftotal\n", $ue, $se, $te;
print "Naive\n";
my ($u1, $s1) = times();
my $t1 = $u1 + $s1;
for (1..$IT) {
my @sorted = sort {-M $b <=> -M $a} @files;
}
my ($u2, $s2) = times();
my $t2 = $u2 + $s2;
my ($ue, $se, $te) = ($u2-$u1, $s2-$s1, $t2-$t1);
printf "Elapsed: %6.2fu %6.2fs %6.2ftotal\n", $ue, $se, $te;
Here's a typical output:
NULL LOOP
Elapsed: 0.00u 0.00s 0.00total
ST
Elapsed: 8.93u 1.54s 10.47total
ST (noblock)
Elapsed: 9.08u 1.34s 10.42total
ST (hash)
Elapsed: 11.14u 2.01s 13.15total
Aux. hash
Elapsed: 9.77u 1.80s 11.57total
Naive
Elapsed: 7.19u 12.88s 20.07total
-
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|