Mark Dominus on 12 Jan 2004 03:35:18 -0000 |
James E Keenan <jkeen@verizon.net>: > CODE A: 140 wallclock secs > (139.73 usr + 0.00 sys = 139.73 CPU) @ 0.07/s (n=10) The '0.00' system time is apparently the result of the way Windows does CPU time accounting; I guess that the Windows version of the Unix 'times' call doesn't distinguish between user and system times, or some such. So when I said it was 'bullshit', I was wrong. Sorry about that. > I've tried two different ways of using the Benchmark module. In > each I _think_ I'm following the coding described in the Benchmark > documentation. You never showed us your complete benchmarking code, but here's what I bet you did: ? my @files; ? opendir D, $DIR or die; ? @files = readdir D; ? ? timethese(10**7, { ? 'CODE A' => '@sorted = sort { -M $b <=> -M $a } @files;', ? 'CODE B' => '@sorted = map { $_->[0] } ? sort {$b->[1] <=> $a->[1]} ? map {[$_, -M $_]} @files;', ? 'CODE C' => '$date{$_} = -M $_ for @files; ? @sorted = sort {$date{$b} <=> $date{$a} } @files; ? undef %date;', ? 'CODE D' => '@sorted = map $_->[0], ? sort {$b->[1] <=> $a->[1]} ? map [$_, -M $_], @files;', ? } ? ); The problem here is that 'Benchmark' uses 'eval' to compile and run the strings that you supplied as if they were code. But it does the 'eval' internally, inside of Benchmark.pm, and that is outside the scope of the '@files' variable, which you declared to be private to your main file. I don't know that you have 'my @files', because you didn't show us the complete code. But that's my shoot in the dark about what is going wrong. If you do have it, you should take it out. Note that this also explains why you get more reasonable results from the function-reference version of the benchmark. > I'm wondering if anyone can spot what's going wrong Usually, when folks ask this question, we tell them that we can't help much without seeing the complete code. I might have gotten lucky this time, but that's still good advice. Regards, -D. - **Majordomo list services provided by PANIX <URL:http://www.panix.com>** **To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**
|
|