Skip to content

Instantly share code, notes, and snippets.

@key-amb key-amb/bench.rb
Last active Mar 8, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.