Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 23 lines (16 sloc) 0.58 kb
c6810945 »
2008-08-11 first commit
1 module Measure
2 @count = 0
3 MAX_TASK_NAME_LEN = 30
4
5 def self.time( task_name, total = 1, &block )
6 @count += 1
7 header = "[ Run task #{task_number = @count} #{total} times ]"
8
9 short_name = task_name[0..MAX_TASK_NAME_LEN] + ( task_name.length > MAX_TASK_NAME_LEN ? '...' : '' )
10
11 start_time = Time.now
12
13 puts "#{header} Start '#{short_name}' at #{start_time.to_s.to_s.match(/\d+:\d+:\d+/)[0]}"
14
15 1.upto(total) {
16 block.call
17 }
18
19 end_time = Time.now
20
21 puts "#{header} Spent #{(end_time - start_time).to_i} seconds on '#{short_name}'"
22 end
23 end
Something went wrong with that request. Please try again.