Skip to content

Instantly share code, notes, and snippets.

@cpkenn09y
Created November 9, 2017 00:13
Show Gist options
  • Save cpkenn09y/915571e22e90b07669a33aeb2ad1a7d3 to your computer and use it in GitHub Desktop.
Save cpkenn09y/915571e22e90b07669a33aeb2ad1a7d3 to your computer and use it in GitHub Desktop.
Simple Benchmark
def pretty_format_from_seconds(total_seconds)
milliseconds = total_seconds % 1 * 1000
seconds = total_seconds % 60
minutes = (total_seconds / 60) % 60
hours = total_seconds / (60 * 60)
return format("%02d:%02d:%02d:%02d", hours, minutes, seconds, milliseconds) #=> "01:00:00"
end
start_time_total = Time.now
person_times = Person.all.map do |person|
benchmarking_results = []
start_time = Time.now
person.get_classifications
end_time = Time.now
formatted_time = pretty_format_from_seconds((end_time - start_time))
[person.id, formatted_time]
end
end_time_total = Time.now
overall_time = end_time_total - start_time_total
average_time = overall_time / (Person.count)
overall_time_formatted = pretty_format_from_seconds((end_time_total - start_time_total))
average_time_formatted = pretty_format_from_seconds(average_time)
stats = []
stats << average_time_formatted
stats << overall_time_formatted
stats << Person.count
puts ":: STATS ::"
puts stats
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment