ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-darwin21]
Warming up --------------------------------------
concatenation 449.658k i/100ms
array join 249.847k i/100ms
Calculating -------------------------------------
concatenation 4.375M (± 2.5%) i/s - 22.033M in 5.039031s
array join 2.508M (± 4.3%) i/s - 12.742M in 5.090572s
Comparison:
concatenation: 4375307.9 i/s
array join: 2508357.4 i/s - 1.74x slower
Created
April 11, 2024 12:41
-
-
Save nicolas-brousse/d0c45ad7286a7b79fd0d8ead187c4d91 to your computer and use it in GitHub Desktop.
This file contains 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
# frozen_string_literal: true | |
require "bundler/inline" | |
gemfile(true) do | |
source "https://rubygems.org" | |
gem "benchmark-ips" | |
end | |
first_name = "John" | |
last_name = "Doe" | |
Benchmark.ips do |x| | |
x.report("concatenation") { "#{first_name} #{last_name}" } | |
x.report("array join") { [first_name, last_name].join(" ") } | |
x.compare! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment