Last active
December 1, 2024 14:12
-
-
Save gauravs/c52e35b5d6a4cbe1bc65 to your computer and use it in GitHub Desktop.
#ruby #benchmark
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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!
@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
❯ 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)