Created
January 18, 2024 21:50
-
-
Save lucivaldo/e7e7e7a55e15200709e70dd4b874fbae to your computer and use it in GitHub Desktop.
Classe Ruby para medir o tempo de execução de um código passado como bloco de código
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ElapsedTime | |
def elapsed | |
start_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) | |
yield if block_given? | |
end_time = Process.clock_gettime(Process::CLOCK_MONOTONIC) | |
elapsed_time = "%.2f" % (end_time - start_time) | |
puts "Tempo decorrido: #{elapsed_time} segundos" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment