Skip to content

Instantly share code, notes, and snippets.

@texpert
Last active June 17, 2022 01:08
Show Gist options
  • Save texpert/63c2878592aef2337b10247e5c682c5e to your computer and use it in GitHub Desktop.
Save texpert/63c2878592aef2337b10247e5c682c5e to your computer and use it in GitHub Desktop.
/bin/bash -c "/Users/thunder/.rvm/bin/rvm ruby-2.3.7@mejuri do /Users/thunder/.rvm/rubies/ruby-2.3.7/bin/ruby '/Users/thunder/Library/Application Support/JetBrains/RubyMine2020.2/scratches/scratch.rb'"
Warming up --------------------------------------
Direct interpolation 426.585k i/100ms
Percent interpolation
232.103k i/100ms
Plus concatenation 507.047k i/100ms
Calculating -------------------------------------
Direct interpolation 4.393M (± 0.3%) i/s - 43.938M in 10.005452s
Percent interpolation
2.302M (± 0.3%) i/s - 23.210M in 10.086796s
Plus concatenation 5.125M (± 0.4%) i/s - 51.212M in 10.000257s
with 95.0% confidence
Comparison:
Plus concatenation: 5124894.8 i/s
Direct interpolation: 4392761.8 i/s - 1.17x (± 0.01) slower
Percent interpolation: 2301505.3 i/s - 2.23x (± 0.01) slower
with 95.0% confidence
-----------------------------------------------------------------------------
/bin/bash -c "/Users/thunder/.rvm/bin/rvm ruby-2.4.9 do /Users/thunder/.rvm/rubies/ruby-2.4.9/bin/ruby '/Users/thunder/Library/Application Support/JetBrains/RubyMine2020.2/scratches/scratch.rb'"
Warming up --------------------------------------
Direct interpolation 448.798k i/100ms
Percent interpolation
233.322k i/100ms
Plus concatenation 462.810k i/100ms
Calculating -------------------------------------
Direct interpolation 4.466M (± 0.2%) i/s - 44.880M in 10.050223s
Percent interpolation
2.371M (± 0.5%) i/s - 23.799M in 10.047935s
Plus concatenation 5.051M (± 1.0%) i/s - 50.446M in 10.019332s
with 95.0% confidence
Comparison:
Plus concatenation: 5051188.0 i/s
Direct interpolation: 4465979.8 i/s - 1.13x (± 0.01) slower
Percent interpolation: 2370744.8 i/s - 2.13x (± 0.02) slower
with 95.0% confidence
--------------------------------------------------------------------------
/bin/bash -c "/Users/thunder/.rvm/bin/rvm ruby-2.5.8 do /Users/thunder/.rvm/rubies/ruby-2.5.8/bin/ruby '/Users/thunder/Library/Application Support/JetBrains/RubyMine2020.2/scratches/scratch.rb'"
Warming up --------------------------------------
Direct interpolation 471.397k i/100ms
Percent interpolation
236.414k i/100ms
Plus concatenation 468.578k i/100ms
Calculating -------------------------------------
Direct interpolation 4.646M (± 0.2%) i/s - 46.668M in 10.045768s
Percent interpolation
2.316M (± 0.3%) i/s - 23.169M in 10.006941s
Plus concatenation 4.570M (± 0.6%) i/s - 45.921M in 10.062382s
with 95.0% confidence
Comparison:
Direct interpolation: 4645824.9 i/s
Plus concatenation: 4570170.5 i/s - 1.02x (± 0.01) slower
Percent interpolation: 2316002.5 i/s - 2.01x (± 0.01) slower
with 95.0% confidence
----------------------------------------------------------------------------
/bin/bash -c "/Users/thunder/.rvm/bin/rvm ruby-2.6.6 do /Users/thunder/.rvm/rubies/ruby-2.6.6/bin/ruby '/Users/thunder/Library/Application Support/JetBrains/RubyMine2020.2/scratches/scratch.rb'"
Warming up --------------------------------------
Direct interpolation 509.128k i/100ms
Percent interpolation
256.033k i/100ms
Plus concatenation 549.347k i/100ms
Calculating -------------------------------------
Direct interpolation 4.917M (± 0.3%) i/s - 49.385M in 10.045288s
Percent interpolation
2.489M (± 1.0%) i/s - 24.835M in 10.009935s
Plus concatenation 5.350M (± 0.5%) i/s - 53.836M in 10.070162s
with 95.0% confidence
Comparison:
Plus concatenation: 5349932.8 i/s
Direct interpolation: 4917308.6 i/s - 1.09x (± 0.01) slower
Percent interpolation: 2489130.0 i/s - 2.15x (± 0.02) slower
with 95.0% confidence
---------------------------------------------------------------
Code:
# frozen_string_literal: true
# Install the necessary gems:
# gem install benchmark-ips
# gem install kalibera
# gem install benchmark-ips
# gem install kalibera
require 'benchmark/ips'
require 'active_support'
# Enable and start GC before each job run. Disable GC afterwards.
#
# Inspired by https://www.omniref.com/ruby/2.2.1/symbols/Benchmark/bm?#annotation=4095926&line=182
class GCSuite
def warming(*)
run_gc
end
def running(*)
run_gc
end
def warmup_stats(*)
end
def add_report(*)
end
private
def run_gc
GC.enable
GC.start
GC.disable
end
end
suite = GCSuite.new
n = 1
s1 = "Test #{n} string"
s2 = 'Test %s string' % n
s3 = 'Test ' + n.to_s + ' string'
Benchmark.ips do |x|
x.config(time: 10, warmup: 5, stats: :bootstrap, confidence: 95)
x.report('Direct interpolation') do
"Test #{n} string"
end
x.report('Percent interpolation') do
'Test %s string' % n
end
x.report('Plus concatenation') do
'Test ' + n.to_s + ' string'
end
x.compare!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment