Skip to content

Instantly share code, notes, and snippets.

@evanphx
Created June 4, 2011 20:13
Show Gist options
  • Save evanphx/1008305 to your computer and use it in GitHub Desktop.
Save evanphx/1008305 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
top = Simple.new
puts Benchmark.measure {
outer = 100
total = 100000
per = 100
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
found = 0
x = top
while x
found += 1
x = x.next
end
p found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment