Skip to content

Instantly share code, notes, and snippets.

@Omochice
Last active November 5, 2021 13:17
Show Gist options
  • Save Omochice/4722b2421ee384b86ec2dcab94915b5d to your computer and use it in GitHub Desktop.
Save Omochice/4722b2421ee384b86ec2dcab94915b5d to your computer and use it in GitHub Desktop.
require "benchmark"
Benchmark.bm do |x|
count = 1000
data = [1, 2]
x.report("case1") do
count.times do
_ = "#{data[0]} #{data[1]}"
end
end
x.report("case2") do
count.times do
_ = data.to_s
end
end
x.report("case3") do
count.times do
_ = data.join(" ")
end
end
end
@Omochice
Copy link
Author

Omochice commented Nov 5, 2021

case1 0.000424 0.000110 0.000534 ( 0.000531)
case2 0.003387 0.000013 0.003400 ( 0.003419)

@Omochice
Copy link
Author

Omochice commented Nov 5, 2021

   user     system      total        real

case1 0.000631 0.000150 0.000781 ( 0.000778)
case2 0.004301 0.000231 0.004532 ( 0.004553)
case3 0.001171 0.000000 0.001171 ( 0.001218)

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