[Rake-devel] rake speedup for several thousand tasks
Niklas von Öhsen
niklas.von-oehsen at scai.fhg.de
Wed Mar 24 11:48:49 EST 2004
Hi there,
I just got acquainted to rake and want to use it to automate
some scientific calculations (I think, its great!). This involves
definition of several thousand tasks. I found that the usual rake "file"
and "task" syntax is quite slow for this. Thus I added new methods for a
faster task definition. The original time needed for the definition of
about 7000 file tasks with one additional dependence was 150 sec. Using
the code below this goes down to 1.2 sec. A speedup of more than 10000% :-)
It sacrifices flexibility and beauty of syntax to raw speed, but if that
is what you need ...
Maybe this interesting for somebody out there? Feel free to use it.
Niklas
# enhance rake task definition for large numbers of tasks
#
# normal rake usage:
# file "name" => "dependency" do |x|
# do_something(x)
# end
#
#This gets slow for a few thousand tasks, due to argument handling.
#
# fast definition for string arguments:
#
# quickfile "name", "dependency" do |x|
# do_something(x)
# end
class Task
def enhancedep(dep, &block)
@prerequisites << dep
@actions << block if block_given?
self
end
class << self
#makes faster task definition possible.
def define_quicktask(name, dep, &block)
if (String === name) and (String === dep)
lookup(name).enhancedep(dep,&block)
else
raise "use quicktask only with strings"
end
end
end
end
# Define a task with a string name and one string dependency
# This has improved performance over "task"
def quicktask(name,dep,&block)
Task.define_quicktask(name,dep,&block)
end
# Define a file task with a string name and one string dependency
# see quicktask
def quickfile(name,dep,&block)
FileTask.define_quicktask(name,dep,&block)
end
--
------------------------------------------------------------
Niklas von Öhsen
More information about the Rake-devel
mailing list