tiendung / ruby-nlp

Ruby Binding for Stanford Pos-Tagger and Name Entity Recognizer

This URL has Read+Write access

tiendung (author)
Mon Aug 11 03:49:48 -0700 2008
ruby-nlp / measure.rb
100644 23 lines (16 sloc) 0.58 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
module Measure
  @count = 0
  MAX_TASK_NAME_LEN = 30
  
  def self.time( task_name, total = 1, &block )
    @count += 1
    header = "[ Run task #{task_number = @count} #{total} times ]"
 
    short_name = task_name[0..MAX_TASK_NAME_LEN] + ( task_name.length > MAX_TASK_NAME_LEN ? '...' : '' )
 
    start_time = Time.now
 
    puts "#{header} Start '#{short_name}' at #{start_time.to_s.to_s.match(/\d+:\d+:\d+/)[0]}"
 
    1.upto(total) {
      block.call
    }
 
    end_time = Time.now
 
    puts "#{header} Spent #{(end_time - start_time).to_i} seconds on '#{short_name}'"
  end
end