Sha256: e405ba890b9849e6970ca3c72aee48ec94939c2a05bf6614e8b1d9d6bb024813

Contents?: true

Size: 738 Bytes

Versions: 8

Compression:

Stored size: 738 Bytes

Contents

#!/usr/bin/env ruby

$: << '.'
$: << '../lib'
$: << '../ext'

require 'objspace'
require 'oj'
require 'json'
require 'get_process_mem'

def record_allocation
  GC.start
  GC.start

  mem = GetProcessMem.new
  puts "Before - Process Memory: #{mem.mb} mb"
  puts "Before - Objects count: #{ObjectSpace.each_object.count}"
  puts "Before - Symbols count: #{Symbol.all_symbols.size}"

  yield

  GC.start
  GC.start
  GC.start

  puts "After - Process Memory: #{mem.mb} mb"
  puts "After - Objects count: #{ObjectSpace.each_object.count}"
  puts "After - Symbols count: #{Symbol.all_symbols.size}"
end

record_allocation do
  data = 1_000_000.times.map { |i| "string_number_#{i}".to_sym } # array of symbols
  Oj.dump(data, mode: :rails)
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
oj-3.7.12 test/mem.rb
oj-3.7.5 test/mem.rb
oj-3.7.1 test/mem.rb
oj-3.7.0 test/mem.rb
oj-3.6.13 test/mem.rb
oj-3.6.12 test/mem.rb
oj-3.6.11 test/mem.rb
oj-3.6.10 test/mem.rb