Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class SimpleBenchmarker
- def self.go(how_many=1, &block)
- puts "------------- Benchmarking started -------------"
- block_times_array = []
- start_time = Time.now
- puts "Start Time:\t#{start_time}\n\n"
- how_many.times do |a|
- print "."
- block_start_time = Time.now
- block.call
- block_end_time = Time.now
- block_time = block_end_time - block_start_time
- block_times_array << block_time
- end
- print "\n\n"
- end_time = Time.now
- puts "End time:\t#{end_time}\n"
- puts "------------- Benchmarking finished -------------\n\n"
- puts "Result:\t\t#{end_time.round(2) - start_time.round(2)} seconds\n\n"
- puts "Our runtimes from quickest to slowests are:"
- puts block_times_array.sort
- end
- end
- print "How many runs will we benchmark? "
- userSelectedTimes = gets.chomp.to_i
- SimpleBenchmarker.go (userSelectedTimes) do
- time = rand(0.1..1.0)
- sleep time
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement