mirror of
https://github.com/lloeki/ruby-benchmarks.git
synced 2025-12-06 08:54:39 +01:00
Add format vs interpolation
This commit is contained in:
parent
f42114b16a
commit
cf3a374bf4
2 changed files with 28 additions and 0 deletions
16
format-string/example.rb
Executable file
16
format-string/example.rb
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'benchmark/ips'
|
||||
|
||||
value = 'value'
|
||||
|
||||
Benchmark.ips do |x|
|
||||
x.time = 5
|
||||
x.warmup = 0.5
|
||||
|
||||
x.report('format') { format('key:%s', value) }
|
||||
x.report('#{}') { "key:#{value}" }
|
||||
|
||||
x.compare!
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue