Created
April 26, 2019 20:40
-
-
Save mec/24d4e97b679fcccdd7f787a2034ad02e to your computer and use it in GitHub Desktop.
Rails perf helper
This file contains hidden or 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
| require 'benchmark' | |
| def print_memory_usage | |
| memory_before = `ps -o rss= -p #{Process.pid}`.to_i | |
| yield | |
| memory_after = `ps -o rss= -p #{Process.pid}`.to_i | |
| puts "Memory: #{((memory_after - memory_before) / 1024.0).round(2)} MB" | |
| end | |
| def print_time_spent | |
| time = Benchmark.realtime do | |
| yield | |
| end | |
| puts "Time: #{time.round(2)}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment