On Feb 15, 2005, at 5:16 PM, Derek Lewis wrote: > I expected the second one to be slightly faster, but was surprised to > see that it was actually slightly slower. I ran each one about 10-15 > times, and eyeballed an average. The results from each run after the > first were pretty consistant. > > It's just a curiosity, but does anyone know what might cause them to be > 'backwards' like that? :) Use ParseTree and you can see why!!! <576> echo "a=/blah/; 's' =~ a" | parse_tree_show -f (cut for readability) [:lasgn, :a, [:lit, /blah/]], [:call, [:str, "s"], :=~, [:array, [:lvar, :a]]]]]]]] <577> echo "'s' =~ /blah/" | parse_tree_show -f (cut for readability) [:match3, [:lit, /blah/], [:str, "s"]]]]]]] Basically, the inline regex avoids the lvar lookup and the call and shoots straight into a match3 node. The lvar is probably not _that_ expensive, but method dispatch is not terribly cheap. -- ryand-ruby / zenspider.com - http://blog.zenspider.com/ http://rubyforge.org/projects/ruby2c/ http://rubyforge.org/projects/parsetree/ http://www.zenspider.com/seattle.rb