On Fri, Mar 7, 2008 at 9:02 AM, Robert Klemme
What version did you test with? I get much more dramatic differences:
FreeBSD was way faster (probably due to optimized compiling) but the
differences were about the same. This is on the same machine...
FreeBSD:
Rehearsal -----------------------------------------------------------
s.gsub(re){|x| x * 2} 9.523438 0.015625 9.539062 ( 9.875376)
s.gsub(re){|x| x << x} 8.453125 0.031250 8.484375 ( 9.576175)
s.gsub(re, '\1\1') 3.320312 0.039062 3.359375 ( 3.482295)
s.gsub(re, '\&\&') 3.429688 0.000000 3.429688 ( 3.545766)
s.gsub(/./){|x| x * 2} 9.523438 0.015625 9.539062 ( 9.885323)
s.gsub(/./){|x| x << x} 8.460938 0.015625 8.476562 ( 9.092159)
s.gsub(/(.)/, '\1\1') 3.312500 0.007812 3.320312 ( 3.436467)
s.gsub(/./, '\&\&') 3.117188 0.007812 3.125000 ( 3.251097)
------------------------------------------------- total: 49.273438sec
user system total real
s.gsub(re){|x| x * 2} 9.539062 0.007812 9.546875 ( 9.913748)
s.gsub(re){|x| x << x} 8.312500 0.023438 8.335938 ( 8.757943)
s.gsub(re, '\1\1') 3.335938 0.000000 3.335938 ( 3.456838)
s.gsub(re, '\&\&') 3.335938 0.007812 3.343750 ( 3.463104)
s.gsub(/./){|x| x * 2} 9.351562 0.031250 9.382812 ( 9.720232)
s.gsub(/./){|x| x << x} 8.343750 0.023438 8.367188 ( 8.666177)
s.gsub(/(.)/, '\1\1') 3.304688 0.031250 3.335938 ( 3.447005)
s.gsub(/./, '\&\&') 3.093750 0.039062 3.132812 ( 3.404753)
WinXP
Rehearsal -----------------------------------------------------------
s.gsub(re){|x| x * 2} 25.844000 0.235000 26.079000 ( 26.062000)
s.gsub(re){|x| x << x} 22.906000 0.312000 23.218000 ( 23.250000)
s.gsub(re, '\1\1') 8.016000 0.391000 8.407000 ( 8.406000)
s.gsub(re, '\&\&') 8.000000 0.484000 8.484000 ( 8.485000)
s.gsub(/./){|x| x * 2} 25.437000 0.438000 25.875000 ( 25.875000)
s.gsub(/./){|x| x << x} 22.766000 0.437000 23.203000 ( 23.218000)
s.gsub(/(.)/, '\1\1') 7.875000 0.656000 8.531000 ( 8.532000)
s.gsub(/./, '\&\&') 7.609000 0.500000 8.109000 ( 8.109000)
------------------------------------------------ total: 131.906000sec
user system total real
s.gsub(re){|x| x * 2} 25.750000 0.609000 26.359000 ( 26.359000)
s.gsub(re){|x| x << x} 23.469000 0.266000 23.735000 ( 23.734000)
s.gsub(re, '\1\1') 8.500000 0.609000 9.109000 ( 9.109000)
s.gsub(re, '\&\&') 8.296000 0.672000 8.968000 ( 8.969000)
s.gsub(/./){|x| x * 2} 26.032000 0.391000 26.423000 ( 26.422000)
s.gsub(/./){|x| x << x} 23.234000 0.390000 23.624000 ( 23.625000)
s.gsub(/(.)/, '\1\1') 8.734000 0.547000 9.281000 ( 9.282000)
s.gsub(/./, '\&\&') 8.235000 0.656000 8.891000 ( 8.890000)
My personal favorite, though, is still s.gsub(/./) {|x| x * 2}.
Todd