mirror of
https://github.com/lloeki/ruby-benchmarks.git
synced 2025-12-06 00:44:39 +01:00
Use benchmark-ips
This commit is contained in:
parent
484269dba2
commit
f42114b16a
4 changed files with 34 additions and 5 deletions
3
Gemfile
Normal file
3
Gemfile
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
source 'https://rubygems.org'
|
||||||
|
|
||||||
|
gem 'benchmark-ips'
|
||||||
13
Gemfile.lock
Normal file
13
Gemfile.lock
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
GEM
|
||||||
|
remote: https://rubygems.org/
|
||||||
|
specs:
|
||||||
|
benchmark-ips (2.12.0)
|
||||||
|
|
||||||
|
PLATFORMS
|
||||||
|
arm64-darwin-22
|
||||||
|
|
||||||
|
DEPENDENCIES
|
||||||
|
benchmark-ips
|
||||||
|
|
||||||
|
BUNDLED WITH
|
||||||
|
2.3.7
|
||||||
|
|
@ -1,5 +1,12 @@
|
||||||
```
|
```
|
||||||
user system total real
|
Warming up --------------------------------------
|
||||||
block 0.961390 0.008933 0.970323 ( 0.978850)
|
block 1.000 i/100ms
|
||||||
ensure 0.752044 0.006407 0.758451 ( 0.763439)
|
ensure 1.000 i/100ms
|
||||||
|
Calculating -------------------------------------
|
||||||
|
block 1.099 (± 0.0%) i/s - 6.000 in 5.460202s
|
||||||
|
ensure 1.400 (± 0.0%) i/s - 8.000 in 5.713243s
|
||||||
|
|
||||||
|
Comparison:
|
||||||
|
ensure: 1.4 i/s
|
||||||
|
block: 1.1 i/s - 1.27x slower
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'benchmark'
|
require 'benchmark/ips'
|
||||||
|
|
||||||
class Example
|
class Example
|
||||||
def initialize
|
def initialize
|
||||||
|
|
@ -20,10 +21,15 @@ class Example
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Benchmark.bm(12) do |x|
|
Benchmark.ips do |x|
|
||||||
|
x.time = 5
|
||||||
|
x.warmup = 0.5
|
||||||
|
|
||||||
ex = Example.new
|
ex = Example.new
|
||||||
n = 10_000_000
|
n = 10_000_000
|
||||||
|
|
||||||
x.report('block') { n.times { ex.using_block } }
|
x.report('block') { n.times { ex.using_block } }
|
||||||
x.report('ensure') { n.times { ex.using_ensure } }
|
x.report('ensure') { n.times { ex.using_ensure } }
|
||||||
|
|
||||||
|
x.compare!
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue