problem with clock()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include<iostream>
#include<time.h>
using namespace std;
int main()
{
    system("date");

    clock_t start = clock();

         int i=9*8;
         while(i--)
         {
             int j=9999999;
             while(j--);
         }

    clock_t end = clock();

    double elapsed = ((double) (end - start)) / CLOCKS_PER_SEC;
    cout<<"elapsed:"<<elapsed<<"\n";
    system("date");
}


system info :SunOS sundev2 5.9 Generic_Virtual sun4u sparc SUNW,Sun-Fire-V245
g++ (GCC) 3.4.6

It takes around 5 secs to execute,but clock returns 17 secs

1
2
3
4
$./a.out
Tue Jul 27 05:14:24 PDT 2010
elapsed:17.9997
Tue Jul 27 05:14:29 PDT 2010
Topic archived. No new replies allowed.