Sha256: 57ad25221f3a43b1181126a4d98663483bb4e6e94c0f8a34717a328cee727877

Contents?: true

Size: 1.17 KB

Versions: 12

Compression:

Stored size: 1.17 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'English'
$LOAD_PATH << '.'
$LOAD_PATH << File.join(__dir__, '../lib')
$LOAD_PATH << File.join(__dir__, '../ext')

require 'oj'

filename = 'tmp.json'
File.open(filename, 'w') { |f|
  cnt = 0
  f.puts('{')
  ('a'..'z').each { |a|
    ('a'..'z').each { |b|
      ('a'..'z').each { |c|
        ('a'..'z').each { |d|
          f.puts(%|"#{a}#{b}#{c}#{d}":#{cnt},|)
          cnt += 1
        }
      }
    }
  }
  f.puts('"_last":0}')
}

def mem
  `ps -o rss= -p #{$PROCESS_ID}`.to_i
end

Oj.default_options = { mode: :strict, cache_keys: false, cache_str: -1 }
start = Time.now
Oj.load_file('tmp.json')
dur = Time.now - start
GC.start
puts "no cache duration: #{dur} @ #{mem}"

Oj.default_options = { cache_keys: true }
start = Time.now
Oj.load_file('tmp.json')
dur = Time.now - start
GC.start
puts "initial cache duration: #{dur} @ #{mem}"

start = Time.now
Oj.load_file('tmp.json')
dur = Time.now - start
GC.start
puts "second cache duration: #{dur} @ #{mem}"

10.times { GC.start }
start = Time.now
Oj.load_file('tmp.json')
dur = Time.now - start
GC.start
puts "after several GCs cache duration: #{dur} @ #{mem}"

# TBD check memory use

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
oj-3.16.9 test/perf_once.rb
oj-3.16.8 test/perf_once.rb
oj-3.16.7 test/perf_once.rb
oj-3.16.6 test/perf_once.rb
oj-3.16.5 test/perf_once.rb
oj-3.16.4 test/perf_once.rb
oj-3.16.3 test/perf_once.rb
oj-3.16.2 test/perf_once.rb
oj-3.16.1 test/perf_once.rb
oj-3.16.0 test/perf_once.rb
oj-3.15.1 test/perf_once.rb
oj-3.15.0 test/perf_once.rb