Message-ID: <3502E3F2.3039@quantum.de> Date: Sun, 08 Mar 1998 19:31:14 +0100 From: Tom Chojnacki Reply-To: chojnack AT quantum DOT de Organization: Quantum Software GmbH, Dortmund, Germany MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: odd clock() behaviour Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk Hi! Recently I tried to measure the time some functions executes itself and I used clock() function to do that. I was surprized because sometimes clock() returned different values even though my function performed exactly the same job. I have written a short test: #include #include #include int main() { clock_t start_time, end_time; long i; start_time=clock(); for (i = 0; i < 1000000; i++) { double root=sqrt(2.0); } end_time=clock(); printf("total time=%f\n", (double)(end_time-start_time)/CLOCKS_PER_SEC); } and while executing it I get mostly: "total time=0.549310" but sometimes I get: "total time=0.494379" and sometimes I get: "total time=0.604241" Can anyone explain why something like that happens. Is it possible to cause that I get the same result every time I call clock() function seqence.