in reply to Re: Unexpected: unpack slower than several substr's. Why?
in thread Unexpected: unpack slower than several substr's. Why?

'push(@array, scalar)' (your implementation) is almost 2X slower than '$array[fixed_index] = scalar' (his implementation).

When verifying other people's benchmarks, try not to alter their code. :-)

Replies are listed 'Best First'.
Re: Re: Re: Unexpected: unpack slower than several substr's. Why?
by BrowserUk (Patriarch) on Jan 14, 2003 at 03:03 UTC

    Actually, I had previously tried it using assignment rather than push and the difference was so negligable as to be within the bounds of varience from one run to the next.

    C:\test>226666 Benchmark: running substr_it, unpack_it , each for at least 3 CPU seconds ... substr_it: 4 wallclock secs ( 3.17 usr + 0.00 sys = 3.17 CPU) @ 23 +75.99/s (n=7520) unpack_it: 4 wallclock secs ( 3.38 usr + 0.00 sys = 3.38 CPU) @ 43 +71.56/s (n=14754) Rate substr_it unpack_it substr_it 2376/s -- -46% unpack_it 4372/s 84% -- Results tally C:\test>

    I did verify the original as best I could, but as he didn't supply the whole benchmark I had to make a few guesses.

    I also attempted to improve both as far as I could as you will see from the update to my first post based upon your suggestion :^)

    Older benchmark code for the above results

      I'd have to take back my educated guess and go with BrowserUk. I tried this on Solaris and Linux using several different variations and the substr version always comes out over 40% slower. And I did not see the push being twice as slow as the explicit array assignments on either system.

      Besides platform, the data being operated on would be the only other factor I can think of that might make the original so much different from what others have tried.