Skip to content

Instantly share code, notes, and snippets.

@sferik sferik/gist:747003
Created Dec 19, 2010

Embed
What would you like to do?
String Benchmarks
require "rubygems"
require "rbench"
def single_quoted_string
'aaa' + 'bbb'
end
def double_quoted_string
"aaa" + "bbb"
end
def percent_string
%(aaa) + %(bbb)
end
def percent_q_string
%q(aaa) + %q(bbb)
end
RBench.run(1_000_000) do
column :one, :title => "Single-Quoted String"
column :two, :title => "Double-Quoted String"
column :three, :title => "Percent String"
column :four, :title => "Percent-Q String"
report "String Speed" do
one { single_quoted_string }
two { double_quoted_string }
three { percent_string }
four { percent_q_string }
end
end
__END__
Single-Quoted String | Double-Quoted String | Percent String | Percent-Q String |
------------------------------------------------------------------------------------------------------
String Speed 0.558 | 0.587 | 0.576 | 0.543 |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.