Skip to content

Instantly share code, notes, and snippets.

@newtonapple
Created November 3, 2009 09:09
Show Gist options
  • Save newtonapple/224910 to your computer and use it in GitHub Desktop.
Save newtonapple/224910 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'rbench'
require 'json'
TIMES = 1000
json = '{"foo1":"bar1","foo2":"bar2","foo3":"bar3"}'
ruby = "{'foo1'=>'bar1', 'foo2'=>'bar2', 'foo3'=>'bar3'}"
RBench.run(TIMES) do
column :json
column :ruby
column :diff, :title => 'ruby / json', :compare => [:ruby, :json]
report 'Long Run' do
json do
1000.times do |i|
JSON.parse(json)
end
end
ruby do
1000.times do |i|
eval(ruby)
end
end
end
end
# JSON | RUBY | ruby / json |
# --------------------------------------------------
# Long Run 12.471 | 14.357 | 1.15x |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment