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
@thadeubrito
Copy link

       user     system      total        real
   3.980000   0.010000   3.990000 (  3.981517)
   2.790000   0.010000   2.800000 (  2.822012)

@chiefGui
Copy link

chiefGui commented Sep 9, 2015

Proof

       user     system      total        real
   4.960000   0.020000   4.980000 (  4.990655)
   3.070000   0.000000   3.070000 (  3.073022)

@gauravs
Copy link
Author

gauravs commented Nov 22, 2015

Vagrant: Virtual-Box provider on Windows

       user     system      total        real
   4.930000   0.010000   4.940000 (  4.953653)
   3.730000   0.010000   3.740000 (  3.751792)

@gauravs
Copy link
Author

gauravs commented Jan 14, 2016

Vagrant on EC2 m4.large

       user     system      total        real
   3.310000   0.440000   3.750000 (  3.754082)
   2.170000   0.460000   2.630000 (  2.625758)

@gauravs
Copy link
Author

gauravs commented Jul 5, 2016

Vagrant: Virtual-Box provider on Windows: KVM interface (Surface Book)

image

       user     system      total        real
   3.280000   0.940000   4.220000 (  4.238997)
   2.270000   0.770000   3.040000 (  3.062164)

@kevinrogerteng
Copy link

kevinrogerteng commented Mar 9, 2017

screen shot 2017-03-09 at 10 03 22 am

       user     system      total        real
   3.850000   0.000000   3.850000  (  3.865135)
   2.580000   0.010000    2.590000  (  2.580340) 

@gauravs
Copy link
Author

gauravs commented Sep 20, 2017

Ubuntu 16.04 on Virtual Box:

       user     system      total        real
   3.050000   0.380000   3.430000 (  3.448118)
   1.960000   0.370000   2.330000 (  2.346749)

Hardware:

Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                2
On-line CPU(s) list:   0,1
Thread(s) per core:    1
Core(s) per socket:    2
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 78
Model name:            Intel(R) Core(TM) i7-6600U CPU @ 2.60GHz
Stepping:              3
CPU MHz:               2808.002
BogoMIPS:              5616.00
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              4096K
NUMA node0 CPU(s):     0,1

@ozeias
Copy link

ozeias commented Sep 20, 2017

screen shot 2017-09-20 at 3 04 37 pm

       user     system      total        real
   3.190000   0.070000   3.260000 (  3.254397)
   2.130000   0.020000   2.150000 (  2.162269)

@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