Skip to content

Instantly share code, notes, and snippets.

@zhouji
Created November 29, 2012 08:48
Show Gist options
  • Save zhouji/4167658 to your computer and use it in GitHub Desktop.
Save zhouji/4167658 to your computer and use it in GitHub Desktop.
calculate time spending in C++
int test1(){
cout<< " OK " << endl;
KestrelServer ks("localhost",22133);
int max = 1000000;
struct timeval start, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
int count = 0;
char data[1024];
data[1023]='\0';
const char * msg = data;
while(count < max){
ks.Send("scoring",msg,5);
count++;
}
gettimeofday(&end, NULL);
seconds = end.tv_sec - start.tv_sec;
useconds = end.tv_usec - start.tv_usec;
mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
cout << mtime << endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment