Kurt StephensNerd Up! | ||||||
performanceRuby: Performance of Symbol Construction
Measurements of Symbol Constructor Expressions. n=10_000_000 ruby 1.8.6 (2008-08-08 patchlevel 286) [i686-linux]:
> /cnu/bin/ruby symbol_benchmark.rb
user system total real
Null Test 0.740000 0.000000 0.740000 ( 0.742914)
'foo_bar' 1.670000 0.000000 1.670000 ( 1.661374)
"foo_bar" 1.620000 0.000000 1.620000 ( 1.625221)
:foo_bar 0.890000 0.000000 0.890000 ( 0.886903)
:'foo_bar' 0.880000 0.000000 0.880000 ( 0.878555)
<br class="clear" />
Ruby : Tight Code, Floppy Performance
So you’re coding some ruby, and you do the obligatory caching of a computation:
def foo(x)
666
end
$cache = nil
def cryptic_cached_foo
($cache ||= [ foo("bar") ]).first
end
def nicey_cached_foo
unless $cache
$cache = [ foo("bar") ]
end
$cache.first
end
A discussion came up at work: is |
||||||
Recent comments
2 weeks 4 days ago
6 weeks 6 days ago
16 weeks 6 days ago
18 weeks 3 days ago
20 weeks 6 days ago
20 weeks 6 days ago
24 weeks 1 day ago
24 weeks 1 day ago
26 weeks 3 hours ago
26 weeks 3 days ago