Project

elapsed

0.0
A long-lived project that still receives updates
You simply pass a code block to the elapsed() function and it will print the summary of execution to the log with the time it took
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Runtime

~> 0.6
~> 0.1
 Project Readme

Measures the Time Elapsed by a Block

DevOps By Rultor.com We recommend RubyMine

rake PDD status Gem Version Test Coverage Yard Docs Hits-of-Code License

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(good: '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

You can also filter out small durations using the over: parameter:

elapsed(Loog::VERBOSE, over: 0.5) do
  # This message will only be logged if the block takes more than 0.5 seconds
  run_something_that_might_be_fast
end

That's it.

How to contribute

Read these guidelines. Make sure your 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.