in reply to Re: Re: Replacing $mon with Jan, Feb, Mar by regex or other means
in thread Replacing $mon with Jan, Feb, Mar by regex or other means

To make a better comparison, you should strftimeLookup do a getMonthNumber as well. Now it's the only case that isn't penalized by an extra subroutine call. Or you could eliminate the call from all cases, the lookup time won't be different depending on the number of the month. Just use a fixed month number (but don't hardcode it as a literal, or else the compiler might pre-calculate some calculations).

Abigail

Replies are listed 'Best First'.
Re: Re: Replacing $mon with Jan, Feb, Mar by regex or other means
by RMGir (Prior) on Apr 25, 2003 at 12:14 UTC
    I did consider that, but since the strftime variant was already losing badly, it didn't seem critical.

    You're right, though, wrapping the fetch of @fixedLocaltime in a sub (returning a ref to the array) call kills the performance of the strftime variant a bit more.

    $ perl testMonth.pl Benchmark: running inlineArrayLookup, preBuiltArrayLookup, strftimeLoo +kup, strftimeSubLookup, substrLookup, each for at least 2 CPU seconds +... inlineArrayLookup: 2 wallclock secs ( 2.12 usr + 0.00 sys = 2.12 CP +U) @ 513847.17/s (n=1089356) preBuiltArrayLookup: 2 wallclock secs ( 2.09 usr + 0.01 sys = 2.10 +CPU) @ 568700.00/s (n=1194270) strftimeLookup: 1 wallclock secs ( 1.81 usr + 0.35 sys = 2.16 CPU) +@ 223003.24/s (n=481687) strftimeSubLookup: 2 wallclock secs ( 1.74 usr + 0.26 sys = 2.00 CP +U) @ 182455.50/s (n=364911) substrLookup: 2 wallclock secs ( 2.19 usr + 0.01 sys = 2.20 CPU) @ +446835.91/s (n=983039) Rate strftimeSubLookup strftimeLookup substrLo +okup inlineArrayLookup preBuiltArrayLookup strftimeSubLookup 182455/s -- -18% +-59% -64% -68% strftimeLookup 223003/s 22% -- +-50% -57% -61% substrLookup 446836/s 145% 100% + -- -13% -21% inlineArrayLookup 513847/s 182% 130% + 15% -- -10% preBuiltArrayLookup 568700/s 212% 155% + 27% 11% --

    --
    Mike

    Edit by tye, change PRE to CODE around long lines