File: tictoc.rb

package info (click to toggle)
jblas 1.2.0-4
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 46,164 kB
  • sloc: java: 11,050; ansic: 4,152; ruby: 2,290; xml: 289; makefile: 132; sh: 22
file content (33 lines) | stat: -rw-r--r-- 474 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# some tools for timing code
#
# Either used as
#
#    tic
#    do something...
#    tic
#
# or as a block
#
#    tictoc do 
#      do something...
#    end
#
# The non-block one might be more handy if you define new variables in your code.

def tic(message=nil)
  if message
    print message + "... "
    $stdout.flush
  end
  $saved_time = Time.new
end

def toc
  print "(#{Time.new - $saved_time} seconds)\n"
end

def tictoc(message=nil)
  tic message
  yield
  toc
end