Skip to content

Instantly share code, notes, and snippets.

@10XL
Created November 23, 2016 20:22
Show Gist options
  • Save 10XL/7079f1fbbcdb27fefe32280503b0d904 to your computer and use it in GitHub Desktop.
Save 10XL/7079f1fbbcdb27fefe32280503b0d904 to your computer and use it in GitHub Desktop.
Ruby(2.3.1) Benchmark-IPS: Windows 10 and WSL
# https://github.com/evanphx/benchmark-ips
require 'benchmark/ips'
Benchmark.ips do |x|
# Configure the number of seconds used during
# the warmup phase (default 2) and calculation phase (default 5)
x.config(:time => 5, :warmup => 2)
# These parameters can also be configured this way
x.time = 5
x.warmup = 2
# Typical mode, runs the block as many times as it can
x.report("addition") { 1 + 2 }
# To reduce overhead, the number of iterations is passed in
# and the block must run the code the specific number of times.
# Used for when the workload is very small and any overhead
# introduces incorrectable errors.
x.report("addition2") do |times|
i = 0
while i < times
1 + 2
i += 1
end
end
# To reduce overhead even more, grafts the code given into
# the loop that performs the iterations internally to reduce
# overhead. Typically not needed, use the |times| form instead.
x.report("addition3", "1 + 2")
# Really long labels should be formatted correctly
x.report("addition-test-long-label") { 1 + 2 }
# Compare the iterations per second of the various reports!
x.compare!
end
// Windows 10
Warming up --------------------------------------
addition 181.926k i/100ms
addition2 182.792k i/100ms
addition3 248.113k i/100ms
addition-test-long-label
176.710k i/100ms
Calculating -------------------------------------
addition 8.576M (± 2.4%) i/s - 42.935M in 5.009042s
addition2 25.136M (± 5.1%) i/s - 125.395M in 5.005303s
addition3 23.727M (± 9.9%) i/s - 117.357M in 5.003721s
addition-test-long-label
8.615M (± 2.6%) i/s - 43.117M in 5.008447s
Comparison:
addition2: 25136275.3 i/s
addition3: 23726965.0 i/s - same-ish: difference falls within error
addition-test-long-label: 8615012.4 i/s - 2.92x slower
addition: 8576381.9 i/s - 2.93x slower
// WSL
Warming up --------------------------------------
addition 129.880k i/100ms
addition2 126.350k i/100ms
addition3 154.878k i/100ms
addition-test-long-label
131.466k i/100ms
Calculating -------------------------------------
addition 9.606M (± 4.6%) i/s - 47.926M in 5.000607s
addition2 29.149M (± 3.6%) i/s - 145.555M in 5.001931s
addition3 27.600M (± 5.8%) i/s - 137.377M in 5.001184s
addition-test-long-label
9.646M (± 3.6%) i/s - 48.248M in 5.008798s
Comparison:
addition2: 29149485.9 i/s
addition3: 27599531.8 i/s - same-ish: difference falls within error
addition-test-long-label: 9645942.7 i/s - 3.02x slower
addition: 9605853.9 i/s - 3.03x slower
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment