From: Intransition Date: 2010-10-07T13:28:36+09:00 Subject: Benchmarks Project and example for `||=` Has anyone ever put together a suite of benchmarks that simply measure interesting Ruby practices? For example, here is a comparison of using ||= vs not using it. n = 1000000 puts "#{n} Times" t = Time.now @b = :b n.times do @b end puts "Simple Read : #{Time.now - t} seconds" t = Time.now n.times do @a ||= :a end puts " Or Equals : #{Time.now - t} seconds" On `ruby 1.8.7 (2010-01-10 patchlevel 249) [x86_64-linux]`: 1000000 Times Simple Read : 0.395487 seconds Or Equals : 0.508428 seconds On `ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]`: 1000000 Times Simple Read : 0.121280356 seconds Or Equals : 0.183629043 seconds Might be an interesting project.