im having trouble timing my loop,

note, this is just part of my main file

#include <iostream>
#include<sys/time.h>

struct timeval tv1, tv2;
  struct timezone tz1,tz2;
  long totalT;
  int const times = 500;

gettimeofday(&tv1, &tz1);

for ( int i = 0; i times; i++)
{
//do something, 
}

gettimeofday(&tv2, &tz2);

 totalT = (tv2.tv_sec - tv1.tv_sec) * 1000000
    + (tv2.tv_usec - tv1.tv_usec);

   cout << "the time it took was: " << totalT << "us" << endl;

when i do my loop for 400 times it does seem to work correctly, but when i do it for more than 500 times it doesnt give me anything, any help on solving this?

Try printing all the values to see which ones are wrong...

Try printing all the values to see which ones are wrong...

they all print correctly

Then I have no idea what you're asking since the problem as you stated it is cryptic at best. Try giving us some details that explain exactly what is going on.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.