-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathbenchmark.rake
More file actions
32 lines (26 loc) · 914 Bytes
/
benchmark.rake
File metadata and controls
32 lines (26 loc) · 914 Bytes
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
31
32
# frozen_string_literal: true
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