SE250:lab-1:hbar055

From Marks Wiki
Revision as of 05:18, 3 November 2008 by Mark (Sọ̀rọ̀ | contribs) (3 revision(s))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This program measures how long it would take for the (+) operation to run for 10 million times (using y++). The program contained a "for Loop" which helped to give an appropriate time.

The procedure for this program is as follows:

  • First i used the 'clock_t t0 = clock();' to record the time at present time.
  • Then a for loop was used to loop 10 million times just using the (+) operator.
  • The line 'printf( "%ld\n", clock() - t0 );' just took the present time after the operation in the for Loop and subtracted it by the time before the for Loop operation.

A few problems came up in the making of this program. The program gave 0 continuously in its execution, this was because the number of loops was too few for the computer to give a proper time record. The result finally gave a proper number of an average of 35ms.

In trying different operations and different types the result gave different values, the result of some of these changes are given as follows:

  • Using 'double y' gave a slower sped of about 75ms
  • Using 'double x' gave a slower speed of about 60ms
  • Using 'y--' gave the same average speed as y++
  • Using 'float y' gave a slower sped of about 50ms
  • Using 'float x' gave a slower speed of about 60ms
  • Using 'long y' gave a slower speed of about 35ms
  • Using 'long x' gave a slower speed of about 60ms