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
12
format-string/README.md
Normal file
12
format-string/README.md
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
```
|
||||
Warming up --------------------------------------
|
||||
format 611.664k i/100ms
|
||||
#{} 1.229M i/100ms
|
||||
Calculating -------------------------------------
|
||||
format 6.037M (± 4.3%) i/s - 30.583M in 5.077835s
|
||||
#{} 12.277M (± 0.4%) i/s - 61.438M in 5.004388s
|
||||
|
||||
Comparison:
|
||||
#{}: 12276995.7 i/s
|
||||
format: 6037136.3 i/s - 2.03x slower
|
||||
```
|
||||
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