Guest User

Untitled

a guest
Apr 19th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. require 'rubygems'
  2. require 'rbench'
  3. require 'json'
  4.  
  5.  
  6. TIMES = 1000
  7.  
  8. json = '{"foo1":"bar1","foo2":"bar2","foo3":"bar3"}'
  9. ruby = "{'foo1'=>'bar1', 'foo2'=>'bar2', 'foo3'=>'bar3'}"
  10.  
  11. RBench.run(TIMES) do
  12. column :json
  13. column :ruby
  14. column :diff, :title => 'ruby / json', :compare => [:ruby, :json]
  15.  
  16.  
  17.  
  18. report 'Long Run' do
  19. json do
  20. 1000.times do |i|
  21. JSON.parse(json)
  22. end
  23. end
  24. ruby do
  25. 1000.times do |i|
  26. eval(ruby)
  27. end
  28. end
  29. end
  30. end
  31.  
  32. # JSON | RUBY | ruby / json |
  33. # --------------------------------------------------
  34. # Long Run 12.471 | 14.357 | 1.15x |
Add Comment
Please, Sign In to add comment