in reply to Symbolic refs aka. dynamic variables again
i think your benchmark is a little off, since it's comparing global scalars to a lexical hash. hopefully this one's more accurate (but i'm no expert.)
Update:here, global vars win in speed, as you quoted. i did not test memory requirements. of course, i meant that lexicals win... what was i looking at when i typed that?
#!perl use Benchmark; my %l_hash; sub use_global_hash { ++$hash{ 'foo' . $_ } for 0 .. 1000 } sub use_global_vars { ++${ 'foo' . $_ } for 0 .. 1000 } sub use_lexical_hash { ++$l_hash{ 'foo' . $_ } for 0 .. 1000 } timethese -10, { use_global_hash => \&use_global_hash, use_global_vars => \&use_global_vars, use_lexical_hash => \&use_lexical_hash, }; __END__ > t-b-symref.pl Benchmark: running use_global_hash, use_global_vars, use_lexical_hash +for at least 10 CPU seconds... use_global_hash: 11 wallclock secs (10.58 usr + 0.00 sys = 10.58 CPU) + @ 744.83/s (n=7884) use_global_vars: 10 wallclock secs (10.54 usr + 0.02 sys = 10.56 CPU) + @ 561.35/s (n=5925) use_lexical_hash: 11 wallclock secs (10.65 usr + 0.00 sys = 10.65 CPU +) @ 794.74/s (n=8460)
~Particle *accelerates*
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Symbolic refs aka. dynamic variables again
by diotalevi (Canon) on Apr 25, 2003 at 02:15 UTC | |
|
Re: Re: Symbolic refs aka. dynamic variables again
by Jenda (Abbot) on Apr 25, 2003 at 10:18 UTC |