RubyFlow The Ruby and Rails community linklog

×

The Ruby and Rails community linklog

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!

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.

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

You can use basic HTML markup (e.g. <a>) or Markdown.

As you are not logged in, you will be
directed via GitHub to signup or sign in