Created
October 5, 2017 13:53
-
-
Save doudou/dc75dbb12dc9daf36798d004e9eceff6 to your computer and use it in GitHub Desktop.
Benchmark of Rake::FileTask#out_of_date? for https://github.com/ruby/rake/pull/224
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This attempts to reproduce the performance regression caused by #183 | |
# | |
# We basically go wide with a bottleneck file and then go wide again. This | |
# causes the "downstream" part (after the bottleneck) to be queried over and | |
# over again with #183 | |
require 'rake' | |
MAX_SIZE = 100 | |
MAX_SIZE.times do |i| | |
FileUtils.touch "down#{i}" | |
end | |
sleep 0.1 | |
MAX_SIZE.times do |i| | |
FileUtils.touch "up#{i}" | |
end | |
sleep 0.1 | |
MAX_SIZE.times do |i| | |
FileUtils.touch "root#{i}" | |
end | |
def setup(size) | |
app = Rake::Application.new | |
downstream = (0...size).map do |i| | |
app.define_task(Rake::FileTask, "down#{i}") | |
end | |
upstream = (0...size).map do |i| | |
app.define_task(Rake::FileTask, "up#{i}") | |
end | |
roots = (0...size).map do |i| | |
app.define_task(Rake::FileTask, "root#{i}") | |
end | |
roots.each do |root_t| | |
root_t.enhance upstream.map(&:name) | |
end | |
upstream.each do |upstream_t| | |
upstream_t.enhance downstream.map(&:name) | |
end | |
tic = Time.now | |
roots.each { |t| t.send(:out_of_date?, Time.now + 1) } | |
Time.now - tic | |
end | |
[10, 20, 30, 40, 50, 60, 70, 80, 90, 100].each do |size| | |
10.times do | |
duration = setup(size) | |
puts "#{size} #{duration}" | |
end | |
end | |
task :default |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment