mosquito-cr / mosquito

A background task runner for crystal applications supporting periodic (CRON) and manually queued jobs
MIT License
227 stars 24 forks source link

use Time.measure instead of Benchmark.measure #57

Closed anapsix closed 3 years ago

anapsix commented 3 years ago

switch to Time.measure in place of Benchmark.measure for simplification and performance, as alternative to https://github.com/robacarp/mosquito/pull/56

Benchmark.measure appears to be slower, compared to Time.measure

require "benchmark"

Benchmark.ips do |x|
  x.report("benchmark") {
    Benchmark.measure do
      Int64.new(2)
    end
  }
  x.report("time") {
    Time.measure do
      Int64.new(2)
    end
  }
end
benchmark 494.87k (  2.02µs) (± 5.95%)  64.0B/op  27.18× slower
     time  13.45M ( 74.34ns) (± 4.62%)   0.0B/op        fastest
robacarp commented 3 years ago

I think I prefer time.measure. The Benchmark system provides a bunch of extra logic which is unnecessary here. Thank you for submitting both pulls.