Kurt Stephens

Nerd Up!

performance

ChicagoRuby Ruby Code Tweaks slides, code and video

Kurt on Wed, 2010-05-05 12:59.

The slides from my ChicagoRuby 2010/5/4 presentation :

http://kurtstephens.com/pub/ruby/ruby_code_tweaks/

All the raw data used to generate the graph should be referenced in the slides.

The code used to generate the slides is here:

http://github.com/kstephens/ruby_code_tweaks

I’m looking to increase the set of code “Problems” to cover other tiny code idioms and platform issues, for example: regular expressions, numerics, etc. If you have ideas, take a look at the code and contact me.

Justin Love gave a fantastic presentation on lambda and closure.

Thanks to everyone who came — hope it was helpful.

Video from the talk:

Ruby Code Performance Tweaks by Kurt Stephens from ChicagoRuby on Vimeo.


Ruby: Performance of Symbol Construction

Kurt on Sun, 2008-11-23 03:54.

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

Kurt on Tue, 2007-10-09 20:04.

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 nicey_cached_foo “better” than cryptic_cached_foo? Obviously, nicey_cached_foo is more readable, but when I find myself doing the same pattern over and over, I prefer the terse cryptic_cached_foo. I expected cryptic_cached_foo to be faster. Oh boy, was I wrong….

Syndicate content

Primary links

Syndicate

Syndicate content

Browse archives

« February 2012  
Mo Tu We Th Fr Sa Su
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29