Well I was almost ready to post a $ENV{SCRIPT_FILENAME} option, but before I did I ran a benchmark on the three options (includes the option of the wrong filename). It seems that the Win32::GetLongPathName is in deed the fastest with the correct filename. Here is my simple Benchmark code:

#!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?

UPDATE: The above code has a glaring error. The subs for env and win32 were flip flopped in the timethese function. The Win32 way is 10 times slower not the ENV way. I apologize for the late night code :^)

In reply to Re: Win32 Apache && File::Basename by trs80
in thread Win32 Apache && File::Basename by Flame

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.