Created
August 30, 2016 16:04
-
-
Save mijoharas/f7968a546d4681ab7f5a83115f5bf2d7 to your computer and use it in GitHub Desktop.
profiling ruby file approaches
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 'ruby-prof' | |
filename = '/tmp/example.txt' | |
File.delete(filename) | |
# profile first method | |
RubyProf.start | |
(1..100_000).each do |i| | |
File.open(filename, 'ab') do |file| | |
file.puts "line: #{i}" | |
end | |
end | |
result = RubyProf.stop | |
filename = '/tmp/example2.txt' | |
# profile second | |
RubyProf.start | |
@file = File.open(filename, 'wb') | |
(1..100_000).each do |i| | |
@file.puts "line: #{i}" | |
end | |
@file.close | |
result2 = RubyProf.stop | |
printer = RubyProf::GraphPrinter.new(result) | |
printer2 = RubyProf::GraphPrinter.new(result2) | |
printer.print(STDOUT, {}) | |
printer2.print(STDOUT, {}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment