This is a good naive way but there are many proper tools developed for this with better accuracy and performance.
github.com/evanphx/benchmark-ips is a great tool and should be used for benchmarks. Also, Time.now is slower and less accurate compared to
Time.now
Process.clock_gettime(Process::CLOCK_MONOTONIC)
require 'benchmark/ips' Benchmark.ips do |x| x.config(:time => 5, :warmup => 2) x.report("Time.now") do Time.now end x.report("Process.clock_gettime(Process::CLOCK_MONOTONIC)") do Process.clock_gettime(Process::CLOCK_MONOTONIC) end end Warming up -------------------------------------- Time.now 151.525k i/100ms Process.clock_gettime(Process::CLOCK_MONOTONIC) 245.057k i/100ms Calculating ------------------------------------- Time.now 2.383M (± 6.2%) i/s - 11.970M in 5.045105s Process.clock_gettime(Process::CLOCK_MONOTONIC) 5.875M (± 2.6%) i/s - 29.407M in 5.009710s
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
This is a good naive way but there are many proper tools developed for this with better accuracy and performance.
github.com/evanphx/benchmark-ips is a great tool and should be used for benchmarks.
Also,
Time.now
is slower and less accurate compared toProcess.clock_gettime(Process::CLOCK_MONOTONIC)