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 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