File: benchmark.rake

package info (click to toggle)
ruby-regexp-parser 2.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 968 kB
  • sloc: ruby: 6,396; sh: 12; makefile: 6
file content (30 lines) | stat: -rw-r--r-- 883 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
BENCHMARKS_DIR = "#{__dir__}/benchmarks"

desc 'Run all IPS benchmarks'
task :benchmark do
  Dir["#{BENCHMARKS_DIR}/*.rb"].sort.each { |file| load(file) }
end

namespace :benchmark do
  desc 'Run all IPS benchmarks and store the comparison results in BENCHMARK.md'
  task :write_to_file do
    require 'stringio'

    string_io = StringIO.new
    with_stdouts(STDOUT, string_io) { Rake.application[:benchmark].invoke }

    File.write "#{BENCHMARKS_DIR}/log",
               "Results of rake:benchmark on #{RUBY_DESCRIPTION}\n\n" +
               string_io.string.gsub(/Warming up.*?Comparison:/m, '')
  end
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