Skip to content

Instantly share code, notes, and snippets.

@evanphx
Created June 4, 2011 16:22
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 evanphx/1008033 to your computer and use it in GitHub Desktop.
Save evanphx/1008033 to your computer and use it in GitHub Desktop.
require 'benchmark'
class Simple
attr_accessor :next
end
def current_mem
`ps -o "%mem rss" -p #{$$}`.split("\n").last.split(/\s+/)[1..-1]
end
saves = 0
puts Benchmark.measure {
outer = 10
total = 100000
per = 100
top = Simple.new
outer.times do
start = current_mem
total.times do
per.times { Simple.new }
s = Simple.new
top.next = s
top = s
saves += 1
end
fin = current_mem
p start
p fin
end
}
p :saves => saves
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment