in reply to Re: Tribute to TMTOWTDI
in thread Tribute to TMTOWTDI
To avoid this problem, you should either declare @a and @b as global variables or pass the code snippets as anonymous subroutine references.
Here's an improved benchmark:
The difference between the solutions is still insignificant. With repeated benchmarks, the order of the solutions will change, and the percentage differences will remain small.#!/usr/bin/perl -w use 5.006; use strict; use Benchmark qw/ cmpthese /; use vars qw/ @a @b /; @a = ('a'..'z'); cmpthese(-3, { '1' => '@b = map uc,@a', '2' => '@b = map uc $_,@a', '3' => '@b = map uc(),@a', '4' => '@b = map uc($_),@a', '5' => '@b = map {uc} @a', '6' => '@b = map {uc $_} @a', '7' => '@b = map {uc()} @a', '8' => '@b = map {uc($_)} @a', }); __END__ Benchmark: running 1, 2, 3, 4, 5, 6, 7, 8, each for at least 3 CPU sec +onds... 1: 4 wallclock secs ( 3.17 usr + 0.01 sys = 3.18 CPU) @ 97 +06.92/s (n=30868) 2: 4 wallclock secs ( 3.18 usr + 0.02 sys = 3.20 CPU) @ 97 +10.31/s (n=31073) 3: 4 wallclock secs ( 3.13 usr + 0.02 sys = 3.15 CPU) @ 97 +73.02/s (n=30785) 4: 4 wallclock secs ( 3.13 usr + 0.01 sys = 3.14 CPU) @ 98 +98.09/s (n=31080) 5: 3 wallclock secs ( 3.17 usr + 0.00 sys = 3.17 CPU) @ 96 +11.67/s (n=30469) 6: 3 wallclock secs ( 3.18 usr + 0.01 sys = 3.19 CPU) @ 96 +50.47/s (n=30785) 7: 4 wallclock secs ( 3.04 usr + 0.02 sys = 3.06 CPU) @ 95 +82.68/s (n=29323) 8: 4 wallclock secs ( 3.32 usr + 0.01 sys = 3.33 CPU) @ 95 +33.33/s (n=31746) Rate 8 7 5 6 1 2 3 4 8 9533/s -- -1% -1% -1% -2% -2% -2% -4% 7 9583/s 1% -- -0% -1% -1% -1% -2% -3% 5 9612/s 1% 0% -- -0% -1% -1% -2% -3% 6 9650/s 1% 1% 0% -- -1% -1% -1% -3% 1 9707/s 2% 1% 1% 1% -- -0% -1% -2% 2 9710/s 2% 1% 1% 1% 0% -- -1% -2% 3 9773/s 3% 2% 2% 1% 1% 1% -- -1% 4 9898/s 4% 3% 3% 3% 2% 2% 1% --
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re: Tribute to TMTOWTDI
by demerphq (Chancellor) on Oct 26, 2001 at 16:59 UTC | |
by chipmunk (Parson) on Oct 26, 2001 at 17:51 UTC | |
by demerphq (Chancellor) on Oct 26, 2001 at 18:24 UTC |