Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nateberkopec committed Sep 1, 2024
1 parent 647458b commit 51e724c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/benchmark/ips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -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|
Expand Down
12 changes: 12 additions & 0 deletions test/test_benchmark_ips.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 51e724c

Please sign in to comment.