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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ozeias finally broke the 1 second time!