1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#!/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
|