/////////////////////////////////////////////////////// // // time2.cpp // // Jeff Ondich, 2/11/98 // // Uses Unix's gettimeofday() to time a nested loop. // /////////////////////////////////////////////////////// #include #include int main( void ) { // Get the loop parameter int N; cout << "N? "; cin >> N; struct timeval startTime, stopTime; gettimeofday( &startTime, 0 ); int counter = 0; for( int i=0; i < N; i++ ) for( int j=0; j < N; j++ ) counter++; gettimeofday( &stopTime, 0 ); cout << (stopTime.tv_sec - startTime.tv_sec) * 1000000 + (stopTime.tv_usec - startTime.tv_usec) << endl; cout << counter << endl; return( 0 ); }