Changeset 2062

Show
Ignore:
Timestamp:
10/29/06 03:01:31
Author:
miyagawa
Message:

support h:mm:ss.ms format. Ugly code!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • misc/stopwatch

    r2058 r2062  
    11#!/usr/bin/perl 
    22use strict; 
     3use POSIX; 
    34use Time::HiRes qw( gettimeofday usleep ); 
    45 
     
    89while (1) { 
    910    my $time = gettimeofday - $start; 
    10     printf "%.2f\r", $time; 
     11    my($hour, $min, $sec, $ss) = hms($time); 
     12    printf "%d:%02d:%02d%s\r", $hour, $min, $sec, $ss; 
    1113    usleep 0.01; 
    1214} 
    1315 
     16sub hms { 
     17    my $sec = shift; 
     18 
     19    my($hour, $min, $ss); 
     20    $min  = POSIX::floor($sec / 60); 
     21    $sec  = $sec - $min * 60; # don't use % 
     22    $hour = $min / 60; 
     23    $min  = $min % 60; 
     24    my $tmp = $sec; 
     25    $sec  = POSIX::floor($sec); 
     26    $ss   = substr(sprintf('%.02f', $tmp - $sec), 1); 
     27 
     28    return ($hour, $min, $sec, $ss); 
     29} 
     30 
     31