Closed paddor closed 9 years ago
Hello. Could you show your benchmark code?
Yeah sure. Here you go: https://gist.github.com/paddor/444682b037ac027d061b
Thank you. Let me simplify the file to reproduce:
require 'benchmark/ips'
def to_percentage(num)
"(%i%%)" % num
end
Benchmark.ips do |x|
x.report("Test 1: #{to_percentage rand(0..100)}") { }
x.report("Test 2: #{to_percentage rand(0..100)}") { }
x.compare!
end
output
ruby compression_benchmark_github_issue.rb
Calculating -------------------------------------
/Users/Juan/.gem/ruby/2.2.0/gems/benchmark-ips-2.0.0/lib/benchmark/ips/job.rb:154:in `printf': malformed format string - %) (ArgumentError)
from /Users/Juan/.gem/ruby/2.2.0/gems/benchmark-ips-2.0.0/lib/benchmark/ips/job.rb:154:in `block in run_warmup'
from /Users/Juan/.gem/ruby/2.2.0/gems/benchmark-ips-2.0.0/lib/benchmark/ips/job.rb:150:in `each'
from /Users/Juan/.gem/ruby/2.2.0/gems/benchmark-ips-2.0.0/lib/benchmark/ips/job.rb:150:in `run_warmup'
from /Users/Juan/.gem/ruby/2.2.0/gems/benchmark-ips-2.0.0/lib/benchmark/ips.rb:37:in `ips'
from compression_benchmark_github_issue.rb:7:in `<main>'
require 'benchmark/ips'
def to_percentage(num)
"(%i%%%%)" % num
end
Benchmark.ips do |x|
x.report("Test: #{to_percentage rand(0..100)}") { }
end
output:
ruby compression_benchmark_github_issue.rb
Calculating -------------------------------------
Test 1: (76%) 162693 i/100ms
Test 2: (78%) 163378 i/100ms
-------------------------------------------------
Test 1: (76%%) 11643580.4 (±7.1%) i/s - 57918708 in 5.004459s
Test 2: (78%%) 11438905.1 (±7.8%) i/s - 56855544 in 5.008368s
Comparison:
Test 1: (76%%): 11643580.4 i/s
Test 2: (78%%): 11438905.1 i/s - 1.02x slower
I just wanted to use a
%
sign in the labels of my benchmarks, then I saw this:Using
%%
instead is a workaround in the calculation round, but in the second round (the results round), I'll see%%
in the output.I know it's not very common, but I was benchmarking some different compression algorithms for a project and also wanted to include the compression ratio in the benchmark report. :)