User Tools

Site Tools


c:timing
char* timestamp() {
	static char buf[64];
	struct tm t;
 
	time_t now = time(NULL);
	localtime_r(&now,&t);
 
	sprintf(buf,"%04d%02d%02d-%02d%02d%02d",t.tm_year+1900,t.tm_mon+1,t.tm_mday,t.tm_hour,t.tm_min,t.tm_sec);
 
	return buf;
}
 
 
/**
 * Returns the number of seconds since the epoch as a double-precision
 * float with microsecond resolution.
 *
 * @return Time since first call to this function
 */
double getCurrentTime() {
	double t;
	struct timeval tstr;
 
	if (gettimeofday(&tstr, NULL) < 0) {
		fprintf(stderr,"gettimeofday failed\n");
		exit(-1);
	}
 
	t=((tstr.tv_sec + tstr.tv_usec/(double)1000000));
 
	return t;
}
 
long long get_usec() {
	struct timeval tv;
	gettimeofday(&tv,NULL);
	return tv.tv_sec*1000000+tv.tv_usec;
}
c/timing.txt · Last modified: 2009/08/13 09:49 by tkbletsc

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki