Recording execution time across Rake tasks

F

Francis Hwang

So I'm moving an old piece of software of mine to be Rake-specific for
a number of reasons, and I'm trying to record execution time elegantly.
I've got two tasks, and I'd like to be able to enclose the whole thing
in a yielded block.

For example, before Rake the whole thing looked like this:

def profile
start_time = Time.now
yield
total = Time.now - start_time
puts "That took #{ total } seconds."
end

profile do
step1
step2
end

Now, my Rake tasks look like:

task :step2 => :step1 do
...
end

task :step1 do
...
end

Which I like, but leaves me wondering if there's an elegant way to
record the execution time of :step1 then :step2. (Maybe this is a
strange request because in theory :step1 might've already been
executed, though in this case it's really not likely.)

I mean, I could just record a global $start_time variable, sure. That's
no fun, though.

Francis
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top