elapsed

Ruby function to track the time elapsed by the execution of a block and print it to the log

MIT License

Stars
1

Measures the Time Elapsed by a Block

Here is how you can measure and log the time of a block:

require 'elapsed'
elapsed do
  run_something_slow
end

You can also send the log message to a log, for example to the Loog:

require 'elapsed'
require 'loog'
elapsed(Loog::VERBOSE) do
  # any code
end

You can also make the message custom:

elapsed(intro: 'File saved') do
  File.save(f, 'Hello, world!')
end

Or, you can make the message even more custom:

elapsed do
  File.save(f, 'Hello, world!')
  throw :"Successfully saved #{File.size(f)} bytes"
end

That's it.

How to contribute

Read these guidelines. Make sure you build is green before you contribute your pull request. You will need to have Ruby 3.0+ and Bundler installed. Then:

bundle update
bundle exec rake

If it's clean and you don't see any error messages, submit your pull request.