benchmarks/json/json.rb in dolos-0.2.0 vs benchmarks/json/json.rb in dolos-0.2.1

- old
+ new

@@ -1,16 +1,14 @@ # frozen_string_literal: true require 'benchmark/ips' +require 'bundler/setup' require 'dolos' require 'dolos_common_parsers/common_parsers' include Dolos include Dolos::CommonParsers - -def ws_rep0 = ws.rep0 - def comma = c(",") def string_literal = (c("\"") >> char_while(->(ch) { ch != "\"" }).opt << c("\"")) def boolean = (c("true").map { true } | c("false").map { false }) @@ -45,16 +43,41 @@ c("{") >> ws_rep0 >> key_lines.opt << ws_rep0 << c("}") end def json_parser = ws_rep0 >> value -json_from_file = File.read('benchmarks/json/random.json') +require 'json/pure' -Benchmark.ips do |x| - x.time = 60 - x.warmup = 15 - x.report('nested json benchmark') do +json_from_file = File.read('benchmarks/json/nested_json_166.json') + +result = json_parser.run(json_from_file) +puts result.success? + +Benchmark.ips do |x| + x.report('nested json 166kb benchmark') do json_parser.run(json_from_file) end + x.report('Pure ruby json: nested json 166kb benchmark') do + JSON.parse(json_from_file) + end + x.compare! +end + +json_from_file1m = File.read('benchmarks/json/nested_json_1m.json') +result1m = json_parser.run(json_from_file1m) +puts result1m.success? + +# require 'json' + +Benchmark.ips do |x| + # x.report('nested json 1mb benchmark') do + # json_parser.run(json_from_file1m) + # end + # x.report('Ruby native: nested json 1mb benchmark') do + # JSON.parse(json_from_file1m) + # end + # x.report('Pure ruby json: nested json 1mb benchmark') do + # JSON.parse(json_from_file1m) + # end x.compare! end