Skip to content

Instantly share code, notes, and snippets.

@thomasfl
Last active March 7, 2016 08:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thomasfl/1a10873c13b0d5038b89 to your computer and use it in GitHub Desktop.
Save thomasfl/1a10873c13b0d5038b89 to your computer and use it in GitHub Desktop.
require 'thread'
require 'date'
# Format number of hours, minutes and seconds since start time:
def elapsed_time_formatted(start_time)
end_time = DateTime.now
total_seconds = ((end_time - start_time) * 24 * 60 * 60).to_i
seconds = total_seconds % 60
minutes = (total_seconds / 60) % 60
hours = total_seconds / (60 * 60)
return format("%02d:%02d:%02d", hours, minutes, seconds)
end
start_time = DateTime.now
done = false
Thread.new do
## Long running tasks go here
4.times do |i|
sleep 1
end
done = true
end
# Print time since start every second:
while (done == false) do
puts elapsed_time_formatted(start_time)
sleep(1)
end
puts "Done."
@thomasfl
Copy link
Author

thomasfl commented Mar 7, 2016

Use this as a skeleton if there is a long running process (like really long running tests) and you want to know for how long it has been going on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment