home *** CD-ROM | disk | FTP | other *** search
/ Amiga MA Magazine 1998 #6 / amigamamagazinepolishissue1998.iso / coders / jËzyki_programowania / amigae / e_v3.2a / src / guide / timing.e < prev    next >
Text File  |  1977-12-31  |  1KB  |  61 lines

  1. OPT LARGE
  2.  
  3. MODULE 'dos/dos'
  4.  
  5. CONST TICKS_PER_MINUTE=TICKS_PER_SECOND*60, LOTS_OF_TIMES=500000
  6.  
  7. DEF x, y, offset
  8.  
  9. PROC fred(n)
  10.   DEF i
  11.   i:=n+x
  12. ENDPROC
  13.  
  14. /* Repeat evaluation of an expression */
  15. PROC repeat(exp)
  16.   DEF i
  17.   FOR i:=0 TO LOTS_OF_TIMES
  18.     Eval(exp) /* Evaluate the expresssion */
  19.   ENDFOR
  20. ENDPROC
  21.  
  22. /* Time an expression, and set-up offset if not done already */
  23. PROC test(exp, message)
  24.   DEF t
  25.   IF offset=0 THEN offset:=time(`0)  /* Calculate offset */
  26.   t:=time(exp)
  27.   WriteF('\s:\t\d ticks\n', message, t-offset)    
  28. ENDPROC
  29.  
  30. /* Time the repeated calls, and calculate number of ticks */
  31. PROC time(x)
  32.   DEF ds1:datestamp, ds2:datestamp
  33.   Forbid()
  34.   DateStamp(ds1)
  35.   repeat(x)
  36.   DateStamp(ds2)
  37.   Permit()
  38.   IF CtrlC() THEN CleanUp(1)
  39. ENDPROC ((ds2.minute-ds1.minute)*TICKS_PER_MINUTE)+ds2.tick-ds1.tick
  40.  
  41. PROC main()
  42.   x:=9999
  43.   y:=1717
  44.   test(`x+y,     'Addition')
  45.   test(`y-x,     'Subtraction')
  46.   test(`x*y,     'Multiplication')
  47.   test(`x/y,     'Division')
  48.   test(`x OR y,  'Bitwise OR')
  49.   test(`x AND y, 'Bitwise AND')
  50.   test(`x=y,     'Equality')
  51.   test(`x<y,     'Less than')
  52.   test(`x<=y,    'Less than or equal')
  53.   test(`y:=1,    'Assignment of 1')
  54.   test(`y:=x,    'Assignment of x')
  55.   test(`y++,     'Increment')
  56.   test(`IF FALSE THEN y ELSE x, 'IF FALSE')
  57.   test(`IF TRUE THEN y ELSE x,  'IF TRUE')
  58.   test(`IF x THEN y ELSE x,     'IF x')
  59.   test(`fred(2),  'fred(2)')
  60. ENDPROC
  61.