Skip to content

Instantly share code, notes, and snippets.

@ohaddahan
Created September 21, 2018 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohaddahan/f59aa5a261cb56e7b1ca96fb97a8e3fb to your computer and use it in GitHub Desktop.
Save ohaddahan/f59aa5a261cb56e7b1ca96fb97a8e3fb to your computer and use it in GitHub Desktop.
Warming up --------------------------------------
dump : 136.247k i/100ms
dump2 : 209.935k i/100ms
Calculating -------------------------------------
dump : 2.095M (± 3.3%) i/s - 10.491M in 5.013742s
dump2 : 4.570M (± 5.9%) i/s - 22.883M in 5.032849s
Comparison:
dump2 :: 4570234.5 i/s
dump :: 2094819.0 i/s - 2.18x slower
require 'benchmark/ips'
def dump(value, **options)
dump_to_io(value, **options)
end
def dump_to_io(value, compress_threshold: nil)
end
def dump2(value, compress_threshold: nil)
dump_to_io2(value, compress_threshold: compress_threshold)
end
def dump_to_io2(value, compress_threshold: nil)
end
require 'memory_profiler'
MemoryProfiler.report { dump(nil) }.pretty_print(to_file: 'report_dump.txt')
MemoryProfiler.report { dump2(nil) }.pretty_print(to_file: 'report_dump2.txt')
Benchmark.ips do |x|
x.config(time: 5, warmup: 1)
x.report("dump :") { dump(nil) }
x.report("dump2 :") { dump2(nil) }
x.compare!
end
Total allocated: 80 bytes (2 objects)
Total retained: 0 bytes (0 objects)
allocated memory by gem
-----------------------------------
80 other
allocated memory by file
-----------------------------------
80 (irb)
allocated memory by location
-----------------------------------
40 (irb):84
40 (irb):98
allocated memory by class
-----------------------------------
80 Hash
allocated objects by gem
-----------------------------------
2 other
allocated objects by file
-----------------------------------
2 (irb)
allocated objects by location
-----------------------------------
1 (irb):84
1 (irb):98
allocated objects by class
-----------------------------------
2 Hash
retained memory by gem
-----------------------------------
NO DATA
retained memory by file
-----------------------------------
NO DATA
retained memory by location
-----------------------------------
NO DATA
retained memory by class
-----------------------------------
NO DATA
retained objects by gem
-----------------------------------
NO DATA
retained objects by file
-----------------------------------
NO DATA
retained objects by location
-----------------------------------
NO DATA
retained objects by class
-----------------------------------
NO DATA
Allocated String Report
-----------------------------------
Retained String Report
-----------------------------------
Total allocated: 0 bytes (0 objects)
Total retained: 0 bytes (0 objects)
allocated memory by gem
-----------------------------------
NO DATA
allocated memory by file
-----------------------------------
NO DATA
allocated memory by location
-----------------------------------
NO DATA
allocated memory by class
-----------------------------------
NO DATA
allocated objects by gem
-----------------------------------
NO DATA
allocated objects by file
-----------------------------------
NO DATA
allocated objects by location
-----------------------------------
NO DATA
allocated objects by class
-----------------------------------
NO DATA
retained memory by gem
-----------------------------------
NO DATA
retained memory by file
-----------------------------------
NO DATA
retained memory by location
-----------------------------------
NO DATA
retained memory by class
-----------------------------------
NO DATA
retained objects by gem
-----------------------------------
NO DATA
retained objects by file
-----------------------------------
NO DATA
retained objects by location
-----------------------------------
NO DATA
retained objects by class
-----------------------------------
NO DATA
Allocated String Report
-----------------------------------
Retained String Report
-----------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment