home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
sa104os2.zip
/
SATHR104.ZIP
/
SATHER
/
CONTRIB
/
PHLIPP.SA
< prev
next >
Wrap
Text File
|
1994-11-15
|
3KB
|
95 lines
-- Copyright (C) International Computer Science Institute, 1994. COPYRIGHT --
-- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject --
-- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in --
-- the file "Doc/License" of the Sather distribution. The license is also --
-- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA. --
--------> Please email comments to "sather-bugs@icsi.berkeley.edu". <----------
-- timer.sa: For timing short things. NON-PORTABLE. This really
-- should be portably integrated into UNIX or SYS. Any volunteers?
--
-- Author: Michael Philippsen <phlipp@icsi.berkeley.edu>
-- Copyright (C) 1994, International Computer Science Institute
------------------------------------------------------------------------
class TIMER is
-- Has a routine for starting a Timer and a Routine that returns
-- the Time Elapsed since the start.
-- Usage may be as follows:
--
-- TIMER::Start;
--
-- Section of your Porgram that should be timed
--
-- #OUT+"Elapsed Time: "+TIMER::Elapsed+" seconds \n";
----------------------------------------------------------------------
private const CLOCKS_PER_SEC:INT:= 1000000; -- clock returns milliseconds
-- see "man 3 clock" for details
-- resolution of clock is
-- 16.667 milliseconds
private const DEBUG:BOOL:=false;
private shared startOfTimer:INT;
------------------------------------------------------------
Start is
if (void(startOfTimer)) then
startOfTimer := C_CLOCK::clock;
end;
startOfTimer := C_CLOCK::clock;
end; --Start
------------------------------------------------------------
Elapsed:FLT is
if void(startOfTimer) then
return startOfTimer.flt;
else
endOfTimer:INT:=C_CLOCK::clock;
if DEBUG then
#OUT+"Elapsed non void start: "+startOfTimer+"\n";
#OUT+" end: "+endOfTimer+"\n";
end;
res:FLT:=((endOfTimer - startOfTimer).flt / CLOCKS_PER_SEC.flt);
if DEBUG then
#OUT+"Seconds: "+res+"\n";
end;
return res;
end;
end; --Elapsed
end; -- TIMER
----------------------------------------------------------------------
external class C_CLOCK is
clock:INT;
end;
----------------------------------------------------------------------
class TEST_TIMER is
include TEST;
main is
class_name("TIMER");
test("illegal Elapsed",TIMER::Elapsed.str,"0");
TIMER::Start;
loop 1000000.times!; end;
unchecked_test("legal Elapsed",TIMER::Elapsed.str,"~0.9");
finish;
end; --main
end; --TEST_TIMER