Skip to content

Instantly share code, notes, and snippets.

@gauravs
Last active December 1, 2024 14:12
Show Gist options
  • Save gauravs/c52e35b5d6a4cbe1bc65 to your computer and use it in GitHub Desktop.
Save gauravs/c52e35b5d6a4cbe1bc65 to your computer and use it in GitHub Desktop.
#ruby #benchmark
#!/usr/bin/env ruby
require 'benchmark'
iterations = 1_000_000
Benchmark.bm do |bm|
# joining an array of strings
bm.report do
iterations.times do
["The", "current", "time", "is", Time.now].join(" ")
end
end
# using string interpolation
bm.report do
iterations.times do
"The current time is #{Time.now}"
end
end
end
@gauravs
Copy link
Author

gauravs commented Dec 14, 2017

Ruby 2.4.2 on WSL 16.04

image

       user     system      total        real
   4.770000   3.400000   8.170000 (  8.303680)
   2.950000   3.640000   6.590000 (  6.682779)

@gauravs
Copy link
Author

gauravs commented Apr 4, 2019

Macbook Pro, i7 32GB, VMWare Fusion

       user     system      total        real
   2.650635   0.844401   3.495036 (  3.495127)
   2.028558   0.816248   2.844806 (  2.844858)

@gauravs
Copy link
Author

gauravs commented Apr 6, 2019

Desktop, i7 32GB, VMWare Workstation

       user     system      total        real
   2.417273   0.868471   3.285744 (  3.294538)
   1.786456   0.755417   2.541873 (  2.543561)

@ozeias
Copy link

ozeias commented Dec 12, 2020

M1 Studio

       user     system      total        real
   1.645968   0.004830   1.650798 (  1.651007)
   1.285832   0.003811   1.289643 (  1.289669)

@gauravs
Copy link
Author

gauravs commented Dec 12, 2020

Gogo's Chute Desktop:

image

       user     system      total        real
   2.005290   0.000000   2.005290 (  2.005366)
   1.417563   0.000000   1.417563 (  1.417575)

@ozeias
Copy link

ozeias commented Feb 1, 2022

Screen Shot 2022-02-01 at 3 47 04 PM

       user     system      total        real
   1.427310   0.001575   1.428885 (  1.429883)
   1.049289   0.000957   1.050246 (  1.050320)

@gauravs
Copy link
Author

gauravs commented Feb 2, 2022

@ozeias thats amazing!

@ozeias
Copy link

ozeias commented Nov 29, 2024

Screenshot 2024-06-10 at 8 32 14 PM

       user     system      total        real
   1.027717   0.000355   1.028072 (  1.029195)
   0.762456   0.000289   0.762745 (  0.763693)

@ozeias
Copy link

ozeias commented Nov 29, 2024

Screenshot 2024-11-29 at 3 56 05 PM

       user     system      total        real
   0.969262   0.008949   0.978211 (  0.978292)
   0.673414   0.001981   0.675395 (  0.675425)

@gauravs
Copy link
Author

gauravs commented Nov 30, 2024

❯ ruby -v
ruby 3.3.6 (2024-11-05 revision 75015d4c1f) [x86_64-linux]

❯ curl -sSL https://gist.githubusercontent.com/gauravs/c52e35b5d6a4cbe1bc65/raw/benchmark.rb | ruby
       user     system      total        real
   1.092085   0.010109   1.102194 (  1.102220)
   0.787855   0.000000   0.787855 (  0.787861)

image

@gauravs
Copy link
Author

gauravs commented Nov 30, 2024

Screenshot 2024-11-29 at 3 56 05 PM

       user     system      total        real
   0.969262   0.008949   0.978211 (  0.978292)
   0.673414   0.001981   0.675395 (  0.675425)

@ozeias finally broke the 1 second time!

@ozeias
Copy link

ozeias commented Dec 1, 2024

@gauravs crazy to look back and see how much faster are the new devices.

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