trs80 has asked for the wisdom of the Perl Monks concerning the following question:
#!perl use strict; use File::Basename; use CGI; use Benchmark; use Win32; my $cgi = CGI->new(); print $cgi->header; print "Hello World<br>"; print "DOS NAME: " . basename($0) . "<BR>"; print "ENV BASENAME: " . basename($ENV{SCRIPT_FILENAME}) . "<br>"; print "Win32 BASENAME: " . basename(Win32::GetLongPathName($0)) . "<br +>"; timethese (100000, { 'basename_env' => sub { basename(Win32::GetLongPathName($0)) +}, 'basename_win32' => sub { basename($ENV{SCRIPT_FILENAME}) }, 'basemane_dollar0' => sub { basename($0) }, } ); 1;
The results
Benchmark: timing 100000 iterations of
basemane_dollar0,
basename_env,
basename_win32...
basemane_dollar0: 5 wallclock secs
( 3.68 usr + 0.00 sys = 3.68 CPU) @ 27203.48/s (n=100000)
basename_env: 121 wallclock secs
(34.99 usr + 81.07 sys = 116.06 CPU) @ 861.65/s (n=100000)
basename_win32: 5 wallclock secs
( 4.24 usr + 0.00 sys = 4.24 CPU) @ 23557.13/s (n=100000)
Now I would like to know why the $ENV way is SO slow. I had expected there might be a little difference, but 10 times slower? At first
I thought is was partly the hash lookup, but even when I did
a sub with the string (path) instead of the hash it
was still slow.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Slow filename lookup on Win32
by Kanji (Parson) on Jan 23, 2002 at 08:34 UTC | |
by trs80 (Priest) on Jan 23, 2002 at 08:45 UTC | |
|
Re: Slow filename lookup on Win32
by Anonymous Monk on Jan 23, 2002 at 08:51 UTC |