#include <iostream>
using namespace std;

#ifdef __cplusplus
extern "C" {
#endif
 
typedef struct {
	long unsigned	tsc_low,
					tsc_high,
					tsc_low1,
					tsc_high1;
} TscMeasurement;
 
#define rdtsc(low,high) \
     __asm__ __volatile__("rdtsc" : "=a" (low), "=d" (high))
 
inline void tsc_start_measurement (TscMeasurement *tm) {
	rdtsc (tm->tsc_low, tm->tsc_high);
}
 
inline void tsc_stop_measurement (TscMeasurement *tm) {
	rdtsc (tm->tsc_low1, tm->tsc_high1);
}
 
inline long long unsigned tsc_get_ticks (const TscMeasurement *tm)
{
	long long unsigned tsc, tsc1;
	tsc = (long long unsigned) tm->tsc_high << 32 |
		((long long unsigned) tm->tsc_low & 0xffffffff);
	tsc1 = (long long unsigned) tm->tsc_high1 << 32 |
		((long long unsigned) tm->tsc_low1 & 0xffffffff);
	return tsc1 - tsc;
}
 
#ifdef __cplusplus
}
#endif

int main() {
		// your code goes here
	TscMeasurement ttime;
	volatile long long i;
	char buf[100];
 
	tsc_start_measurement(&ttime);
	for(i=0; i < 10000000UL; i++) {
		sprintf(buf, "%d   %s%d%f\n", i,"bla-bla-bla", -10, 1.3);
	}
	tsc_stop_measurement(&ttime);
 
	printf ("Time: %llu\n", tsc_get_ticks(&ttime) );
 
	return 0;
}