1

The problem is clock() function is not allowed, but I have no idea how to deal with time() function in thread.

zie tan ny
  • 71
  • 4
  • 1
    probabl;y you can try looking at http://stackoverflow.com/questions/275004/timer-function-to-provide-time-in-nano-seconds-using-c – Pawan Oct 26 '15 at 05:31
  • Why are you using `pthread` and not `std::thread` since you marked the post as C++11? – CJCombrink Oct 26 '15 at 10:30

3 Answers3

1

Since you marked the post C++11, take a look at the chrono library:

#include <chrono>

std::chrono::time_point<std::chrono::system_clock> start, end;
start = std::chrono::system_clock::now();
... // <-- Code that you want to time
end = std::chrono::system_clock::now();
std::cout << "Time : " << std::chrono::duration<double>(end - start).count();
CJCombrink
  • 3,738
  • 1
  • 22
  • 38
0

I think you can use gettimeofday() function to get the start time and end time. While this function work only in Linux. Please refer to [1]:http://linux.die.net/man/2/gettimeofday

For this function in windows, please refer to [2]:Equivalent of gettimeday() for Windows

Community
  • 1
  • 1
JeffQ
  • 94
  • 5
0

Assuming a Linux system, read time(7) then use clock_gettime(2), probably with CLOCK_REALTIME & CLOCK_THREAD_CPUTIME_ID; see also pthread_getcpuclockid(3) & getrusage(2)

BTW, your MAX_THREADS is too big. You should have at most a dozen or two of threads ....

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547