Benchmarking Date.today and Time.now
Curious about how fast Date.today gets processed in comparison to Time.now? I was, so I ran some tests.
Made a library? Written a blog post? Found a useful tutorial? Share it with the Ruby community here or just enjoy what everyone else has found!
Curious about how fast Date.today gets processed in comparison to Time.now? I was, so I ran some tests.
Comments
In your benchmarks, you aren’t just benchmarking a single thing. You’re benchmarking multiple things. The first benchmark involves creating an object, and then converting it into a string.
Benchmark.measure { 100000.times { Time.now } } # => total=0.203 Benchmark.measure { 100000.times { Time.now.to_s } } # => total=6.077
This also explains why month_name_t appears to be faster than your first Time benchmark.
Post a comment