main
1#!/usr/bin/env ruby
2# frozen_string_literal: true
3
4require 'bundler/inline'
5
6gemfile do
7 source 'https://rubygems.org'
8
9 gem 'benchmark-ips', '~> 2.8'
10 gem 'oj'
11end
12
13require 'benchmark/ips'
14require 'json'
15require 'oj'
16
17Oj.default_options = { mode: :strict }
18
19json = JSON.pretty_generate({
20 string: 'spandx',
21 number: 1234,
22 array: ['MIT']
23})
24
25Benchmark.ips do |x|
26 x.report('JSON.parse') { JSON.parse(json) }
27 x.report('OJ.load') { Oj.load(json) }
28 x.compare!
29end