Skip to content

Instantly share code, notes, and snippets.

@andreleoni
Last active February 8, 2019 13:43
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 andreleoni/3cdce2405f631400a6f291b760b742ad to your computer and use it in GitHub Desktop.
Save andreleoni/3cdce2405f631400a6f291b760b742ad to your computer and use it in GitHub Desktop.
Benchmark sobre uso de memória Ruby Module vs Class
# Gem: https://github.com/SamSaffron/memory_profiler
##### Benchmark vendo memória de um módulo
require "memory_profiler"
MemoryProfiler.start
module Teste
extend self
def oi
"teste"
end
end
Teste.oi
report = MemoryProfiler.stop
report.pretty_print
Total allocated: 116315 bytes (1926 objects)
Total retained: 2606 bytes (31 objects)
##### Benchmark vendo memória de uma classe
require "memory_profiler"
MemoryProfiler.start
class Teste
def self.oi
"teste"
end
end
Teste.oi
report = MemoryProfiler.stop
report.pretty_print
Total allocated: 102987 bytes (1699 objects)
Total retained: 2502 bytes (29 objects)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment