Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 |
Add Comment
Please, Sign In to add comment