~ubuntu-branches/ubuntu/trusty/ruby1.9/trusty

« back to all changes in this revision

Viewing changes to lib/rubygems/timer.rb

  • Committer: Bazaar Package Importer
  • Author(s): Stephan Hermann
  • Date: 2008-01-24 11:42:29 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: james.westby@ubuntu.com-20080124114229-jw2f87rdxlq6gp11
Tags: 1.9.0.0-2ubuntu1
* Merge from debian unstable, remaining changes:
  - Robustify check for target_os, fixing build failure on lpia.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# This file defines a $log variable for logging, and a time() method for recording timing
 
3
# information.
 
4
#
 
5
#--
 
6
# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
 
7
# All rights reserved.
 
8
# See LICENSE.txt for permissions.
 
9
#++
 
10
 
 
11
 
 
12
$log = Object.new
 
13
def $log.debug(str)
 
14
  STDERR.puts str
 
15
end
 
16
 
 
17
def time(msg, width=25)
 
18
  t = Time.now
 
19
  return_value = yield
 
20
  elapsed = Time.now.to_f - t.to_f
 
21
  elapsed = sprintf("%3.3f", elapsed)
 
22
  $log.debug "#{msg.ljust(width)}: #{elapsed}s"
 
23
  return_value
 
24
end
 
25