Skip to content

Instantly share code, notes, and snippets.

@rubychan
Created February 22, 2011 03:00
Show Gist options
  • Save rubychan/838139 to your computer and use it in GitHub Desktop.
Save rubychan/838139 to your computer and use it in GitHub Desktop.
# create
def Bench.run
string = ''
5_000_000.times do
StringScanner.new string
string << '.'
end
end
# create2
def Bench.run
5_000_000.times do |i|
StringScanner.new i.to_s
end
end
Rubinius HEAD:
user system total real
create 2.321300 0.012382 2.333682 ( 2.410239)
create2 2.233669 0.000398 2.234067 ( 2.256402)
With this monkey patch:
class StringScanner
def initialize(string, dup=false)
@string = StringValue(string) # fix for issue 696: https://github.com/evanphx/rubinius/issues/#issue/696
reset_state
end
end
I get:
user system total real
create 2.115283 0.008810 2.124093 ( 2.214133)
create2 1.944784 0.003430 1.948214 ( 1.979908)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment