Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Note: This is pretty badly written code, I just wrote it as a quick proof for
# To get the growth rate of the array, just look at the jump in memory bytes after every copy. You can see that it's about 1.5~
require 'objspace' # Require this for additional ObjectSpace methods
def memory_calculator
array =
result = {}
100.times do |i|
array << i
memory = ObjectSpace.memsize_of(array)
memory_in_bytes = memory / 8.0
result["#{memory_in_bytes} bytes"] = {
num_elements: array.size,
total_available_memory: "#{memory_in_bytes} bytes",
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment