From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, MSGID_SHORT,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!crdgw1!uunet!seas.gwu.edu!mfeldman From: mfeldman@seas.gwu.edu (Michael Feldman) Newsgroups: comp.lang.ada Subject: Unix/Ada CPU timer Message-ID: <3084@sparko.gwu.edu> Date: 19 Apr 91 15:10:49 GMT Reply-To: mfeldman@seas.gwu.edu (Michael Feldman) Organization: The George Washington University, Washington D.C. List-Id: # This is a shell archive. Remove anything before this line, # then unpack it by saving it in a file and typing "sh file". # # Wrapped by Michael Feldman on Fri Apr 19 11:09:19 1991 # # This archive contains: # unixtime.c cpuclock.ada testclok.ada # unset LANG echo x - unixtime.c cat >unixtime.c <<'@EOF' #include #include /* code for including or porting to Ada returns time from program start to call time */ /* J.H.H. (5-14-87) */ int unixtime() { int t; struct tms bslot, *buffer; buffer = (struct tms *)calloc(1,sizeof(bslot)); times(buffer); t = buffer->tms_utime + buffer->tms_stime + buffer->tms_cutime + buffer->tms_cstime ; return t; } @EOF chmod 644 unixtime.c echo x - cpuclock.ada cat >cpuclock.ada <<'@EOF' package CPUClock is type CPUSecond is digits 6; -- all float operations available procedure ResetCPUTime; function CPUTime return CPUSecond; procedure Put(T: CPUSecond); end CPUClock; With TEXT_IO; package body CPUClock is package CPUSecond_IO is new TEXT_IO.FLOAT_IO(CPUSecond); function UnixTime return integer; pragma interface(C, UnixTime, "unixtime"); SAVED_TIME: INTEGER; function CPUTime return CPUSecond is begin return CPUSecond(UnixTime - Saved_Time)/60.0; end CPUTIME; procedure ResetCPUTime is begin SAVED_TIME := UnixTime; end ResetCPUTime; procedure Put(T: CPUSecond) is begin CPUSecond_IO.PUT(Item=>T,aft=>2,exp=>0); end Put; begin -- initialization of package ResetCPUTime; end CPUClock; @EOF chmod 644 cpuclock.ada echo x - testclok.ada cat >testclok.ada <<'@EOF' with TEXT_IO, CPUClock; use TEXT_IO, CPUClock; procedure TestClok is SavedTime, T: CPUSecond := 0.0; NumberOfTrials: constant INTEGER := 10; MaxIndex: constant INTEGER := 100; A: array(1..MaxIndex,1..MaxIndex) of INTEGER; begin ResetCPUTime; for count in 1..NumberOfTrials loop for waste in 1..20 loop for row in 1..MaxIndex loop for col in 1..MaxIndex loop A(row,col) := row*col; end loop; end loop; end loop; T := CPUTime; put("CPU Time Used was "); put(T-SavedTime); NEW_LINE; put("CPU Time so far "); put(T); NEW_LINE; SavedTime := T; end loop; end TestClok; @EOF chmod 644 testclok.ada exit 0