C: using clock() to measure time in multi-threaded programs

Posted by Shinka on Stack Overflow See other posts from Stack Overflow or by Shinka
Published on 2010-06-03T01:23:43Z Indexed on 2010/06/03 1:34 UTC
Read the original article Hit count: 197

Filed under:

I've always used clock() to measure how much time my application took from start to finish, as;

int main(int argc, char *argv[]) {
  const clock_t START = clock();

  // ...

  const double T_ELAPSED = (double)(clock() - START) / CLOCKS_PER_SEC;
}

Since I've started using POSIX threads this seem to fail. It looks like clock() increases N times faster with N threads. As I don't know how many threads are going to be running simultaneously, this approach fails. So how can I measure how much time has passed ?

© Stack Overflow or respective owner

Related posts about c