From 51e724c33b838b177111c8910e4df1bd809a7b9d Mon Sep 17 00:00:00 2001 From: Nate Berkopec Date: Mon, 2 Sep 2024 07:51:02 +0900 Subject: [PATCH] Tests --- lib/benchmark/ips.rb | 5 ++--- test/test_benchmark_ips.rb | 12 ++++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/benchmark/ips.rb b/lib/benchmark/ips.rb index 93c31df..970b695 100644 --- a/lib/benchmark/ips.rb +++ b/lib/benchmark/ips.rb @@ -79,7 +79,7 @@ def ips(*args) # Quickly compare multiple methods on the same object. # @param methods [Symbol...] A list of method names (as symbols) to compare. # @param receiver [Object] The object on which to call the methods. Defaults to Kernel. - # @param opts [Hash] Additional options for customizing the benchmark. See Job.config for all available options. + # @param opts [Hash] Additional options for customizing the benchmark. # @option opts [Integer] :warmup The number of seconds to warm up the benchmark. # @option opts [Integer] :time The number of seconds to run the benchmark. # @@ -91,9 +91,8 @@ def ips(*args) # def sub; 2-1; end # ips_quick(:add, :sub, warmup: 10) def ips_quick(*methods, on: Kernel, **opts) - ips do |x| + ips(opts) do |x| x.compare! - x.config(opts) if opts methods.each do |name| x.report(name) do |x| diff --git a/test/test_benchmark_ips.rb b/test/test_benchmark_ips.rb index 20d57ef..0dc76a1 100644 --- a/test/test_benchmark_ips.rb +++ b/test/test_benchmark_ips.rb @@ -276,4 +276,16 @@ def test_humanize_duration assert_equal Benchmark::IPS::Helpers.humanize_duration(123456789.0123456789), "123.46 ms" assert_equal Benchmark::IPS::Helpers.humanize_duration(123456789012.3456789012), "123.46 s" end + + def test_quick + Benchmark.ips_quick(:upcase, :downcase, on: "Hello World!", warmup: 0.001, time: 0.001) + + assert $stdout.string.size > 0 + end + + def test_quick_on_kernel + Benchmark.ips_quick(:srand, :rand, warmup: 0.001, time: 0.001) + + assert $stdout.string.size.zero? + end end