Created
February 24, 2015 19:28
-
-
Save eprothro/2b2a89fece090d0a1c43 to your computer and use it in GitHub Desktop.
Simple ruby memory benchmark
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Benchmark | |
def memory_usage | |
`ps -o rss= -p #{Process.pid}`.to_i | |
end | |
def memory | |
m0 = memory_usage | |
yield | |
memory_usage - m0 | |
end | |
def kb | |
0.001 * memory { yield } | |
end | |
def mb | |
0.000001 * memory { yield } | |
end | |
module_function :memory, :mb, :kb, :memory_usage | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment