Skip to content

Instantly share code, notes, and snippets.

@key-amb
Last active March 8, 2016 07:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save key-amb/2b7bf0dcd6c6de23eb88 to your computer and use it in GitHub Desktop.
Save key-amb/2b7bf0dcd6c6de23eb88 to your computer and use it in GitHub Desktop.
jm/toml vs. eMancu/toml-rb vs. fbernier/tomlrb
#!/usr/bin/env ruby
require 'toml'
require 'tomlrb'
require 'benchmark'
toml = <<-EOS
title = "sample"
[params]
id = 101
name = "taro"
[foo.bar]
attr1 = "aaa"
attr2 = "bbb"
attr3 = "ccc"
EOS
n = 100
Benchmark.bm(7) do |x|
# jm/toml and eMancu/toml-rb can't load together because they use same namespace
#x.report('toml') { (1..n).each {|i| TOML::Parser.new(toml).parsed } }
x.report('toml-rb') { (1..n).each {|i| TOML.parse(toml) } }
x.report('tomlrb') { (1..n).each {|i| Tomlrb.parse(toml) } }
end
// toml-rb vs. tomlrb
% ruby bench-toml.rb
user system total real
toml-rb 0.190000 0.010000 0.200000 ( 0.205336)
tomlrb 0.020000 0.000000 0.020000 ( 0.020378)
// toml vs. tomlrb
% ruby tmp/test-toml.rb
user system total real
toml 0.400000 0.000000 0.400000 ( 0.413219)
tomlrb 0.020000 0.000000 0.020000 ( 0.025820)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment