Skip to content

Instantly share code, notes, and snippets.

Created December 2, 2021 15:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
# frozen_string_literal: true
require 'benchmark/ips'
require 'logger'
logger ="/dev/null")
time =
Benchmark.ips do |x|
x.config(:time => 30, :warmup => 30)'"%Y-%m-%dT%H:%M:%S.%6N")') do
end'"%Y-%m-%d")') do
end'"%Y-%m-%d %H:%M:%S")') do
time.strftime("%Y-%m-%d %H:%M:%S")
end'"%a, %d %b %Y %H:%M:%S.%9N")') do
time.strftime("%a, %d %b %Y %H:%M:%S.%9N");
end'Logger#add') do
logger.add(Logger::DEBUG, "benchmark a logger")
end'Logger#info') do"literally just something")


jruby (2.6.8) 2021-10-13 2e01e7199d OpenJDK 64-Bit Server VM 25.242-b08 on 1.8.0_242-b08 +jit [linux-x86_64]
Warming up --------------------------------------"%Y-%m-%dT%H:%M:%S.%6N")
                        38.882k i/100ms"%Y-%m-%d")
                        60.857k i/100ms"%Y-%m-%d %H:%M:%S")
                        39.331k i/100ms"%a, %d %b %Y %H:%M:%S.%9N")
                        30.769k i/100ms
          Logger#add    15.644k i/100ms
         Logger#info    15.224k i/100ms
Calculating -------------------------------------"%Y-%m-%dT%H:%M:%S.%6N")
                        358.261k (± 1.8%) i/s -     10.770M in  30.072651s"%Y-%m-%d")
                        691.334k (± 2.1%) i/s -     20.752M in  30.031624s"%Y-%m-%d %H:%M:%S")
                        430.898k (± 1.9%) i/s -     12.940M in  30.040652s"%a, %d %b %Y %H:%M:%S.%9N")
                        328.948k (± 1.9%) i/s -      9.877M in  30.037065s
          Logger#add    164.153k (± 2.2%) i/s -      4.928M in  30.036509s
         Logger#info    157.895k (± 2.2%) i/s -      4.735M in  30.002263s


jruby (2.6.8) 2021-12-01 0b8223f905 OpenJDK 64-Bit Server VM 25.242-b08 on 1.8.0_242-b08 +jit [linux-x86_64]
Warming up --------------------------------------"%Y-%m-%dT%H:%M:%S.%6N")
                       141.610k i/100ms"%Y-%m-%d")
                       233.302k i/100ms"%Y-%m-%d %H:%M:%S")
                       140.383k i/100ms"%a, %d %b %Y %H:%M:%S.%9N")
                        94.912k i/100ms
          Logger#add    27.087k i/100ms
         Logger#info    25.980k i/100ms
Calculating -------------------------------------"%Y-%m-%dT%H:%M:%S.%6N")
                          1.461M (± 2.2%) i/s -     43.899M in  30.065549s"%Y-%m-%d")
                          4.023M (± 4.3%) i/s -    120.384M in  30.046343s"%Y-%m-%d %H:%M:%S")
                          1.966M (± 2.4%) i/s -     58.961M in  30.011980s"%a, %d %b %Y %H:%M:%S.%9N")
                          1.141M (± 2.1%) i/s -     34.263M in  30.046221s
          Logger#add    304.209k (± 2.5%) i/s -      9.128M in  30.028443s
         Logger#info    290.198k (± 2.0%) i/s -      8.703M in  30.004074s

C Ruby 2.6

ruby 2.6.7p197 (2021-04-05 revision 67941) [x86_64-linux]
Warming up --------------------------------------"%Y-%m-%dT%H:%M:%S.%6N")
                        96.305k i/100ms"%Y-%m-%d")
                       146.544k i/100ms"%Y-%m-%d %H:%M:%S")
                        90.765k i/100ms"%a, %d %b %Y %H:%M:%S.%9N")
                        68.983k i/100ms
          Logger#add    15.632k i/100ms
         Logger#info    15.251k i/100ms
Calculating -------------------------------------"%Y-%m-%dT%H:%M:%S.%6N")
                        793.944k (± 2.7%) i/s -     23.884M in  30.105671s"%Y-%m-%d")
                          1.465M (± 1.6%) i/s -     43.963M in  30.017596s"%Y-%m-%d %H:%M:%S")
                        896.960k (± 2.6%) i/s -     26.957M in  30.074496s"%a, %d %b %Y %H:%M:%S.%9N")
                        688.440k (± 1.8%) i/s -     20.695M in  30.070479s
          Logger#add    156.492k (± 1.6%) i/s -      4.705M in  30.074582s
         Logger#info    151.569k (± 2.5%) i/s -      4.545M in  30.005755s

C Ruby 3.0

Note: logger optimizes away doing anything with /dev/null.

ruby 3.0.3p157 (2021-11-24 revision 3fb7d2cadc) [x86_64-linux]
Warming up --------------------------------------"%Y-%m-%dT%H:%M:%S.%6N")
                        90.836k i/100ms"%Y-%m-%d")
                       137.387k i/100ms"%Y-%m-%d %H:%M:%S")
                        84.030k i/100ms"%a, %d %b %Y %H:%M:%S.%9N")
                        66.937k i/100ms
          Logger#add     1.175M i/100ms
         Logger#info   785.475k i/100ms
Calculating -------------------------------------"%Y-%m-%dT%H:%M:%S.%6N")
                        754.689k (± 0.9%) i/s -     22.709M in  30.093185s"%Y-%m-%d")
                          1.367M (± 1.7%) i/s -     41.079M in  30.065341s"%Y-%m-%d %H:%M:%S")
                        847.641k (± 1.4%) i/s -     25.461M in  30.043280s"%a, %d %b %Y %H:%M:%S.%9N")
                        671.847k (± 1.2%) i/s -     20.215M in  30.093076s
          Logger#add     11.754M (± 1.9%) i/s -    353.639M in  30.098646s
         Logger#info      7.744M (± 3.1%) i/s -    232.501M in  30.052223s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment