diff options
| author | mo khan <mo.khan@gmail.com> | 2020-05-31 12:38:19 -0600 |
|---|---|---|
| committer | mo khan <mo.khan@gmail.com> | 2020-05-31 12:38:19 -0600 |
| commit | cba885096abdb3523306851ea1f44dae0738064a (patch) | |
| tree | afd04b0f771e6deb40c7ea3e352cf1eb81d41a07 /bin | |
| parent | f4452bdfe65b8f3c943c73f66f94f78dff59cb7f (diff) | |
benchmark json parsing
Diffstat (limited to 'bin')
| -rwxr-xr-x | bin/json-benchmark | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/bin/json-benchmark b/bin/json-benchmark new file mode 100755 index 0000000..c678823 --- /dev/null +++ b/bin/json-benchmark @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +require 'bundler/inline' + +gemfile do + source 'https://rubygems.org' + + gem 'benchmark-ips', '~> 2.8' + gem 'oj' +end + +require 'benchmark/ips' +require 'json' +require 'oj' + +Oj.default_options = { mode: :strict } + +json = JSON.pretty_generate({ + string: 'spandx', + number: 1234, + array: ['MIT'] +}) + +Benchmark.ips do |x| + x.report('JSON.parse') { JSON.parse(json) } + x.report('OJ.load') { Oj.load(json) } + x.compare! +end |
