Results 1 to 6 of 6

Thread: Problem with clock() function in gcc/g++

Threaded View

  1. #1
    Join Date
    Mar 2010
    Dhaka, Bangladesh
    Ubuntu 12.04 Precise Pangolin

    Problem with clock() function in gcc/g++

    I just wrote this code:
    #include <stdio.h>
    #include <time.h>
    #include <unistd.h>
    #include <stdlib.h>
    int main() {
            clock_t clk1 = clock();
            printf("%ld\n", clk1);
            int i,r=0;
            for(i = 0; i < 100000; i++) r^=rand();
            printf("%d\n", r);
            clock_t clk2 = clock();
            printf("%ld\n", clk2);
            return 0;
    I also tried using a sleep() before the loop, in both cases, clk1 and clk2 both showing 0, why is that? Am I suppossed aren't they supposed to be showing approximate clock cycle count for the program? What am I doing wrong here?
    Last edited by zobayer1; June 12th, 2013 at 07:54 AM.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts