Sha256: d603887cd6a17cb033286bcad6409a5b9f469237fc573fdf6a94f484ad08d006
Contents?: true
Size: 735 Bytes
Versions: 4
Compression:
Stored size: 735 Bytes
Contents
require 'benchmark/ips' require_relative '../../lib/character_set' if RUBY_VERSION.to_f >= 3.0 && !RUBY_PLATFORM[/java/i] require 'sorted_set' else require 'set' end def benchmark(caption: nil, cases: {}) with_stdouts($stdout, string_io = StringIO.new) do puts caption Benchmark.ips do |x| cases.each { |label, callable| x.report(label, &callable) } x.compare! end end ($benchmark_results ||= {})[caption] = string_io.string end def with_stdouts(*ios) old_stdout = $stdout ios.define_singleton_method(:method_missing) { |*args| each { |io| io.send(*args) } } ios.define_singleton_method(:respond_to?) { |*args| IO.respond_to?(*args) } $stdout = ios yield ensure $stdout = old_stdout end
Version data entries
4 entries across 4 versions & 1 rubygems