changeset 1281:37176fafe11e libavcodec

some benchmarking code
author michaelni
date Fri, 23 May 2003 18:04:34 +0000
parents 8623c2e29555
children 8988af3ae1e8
files common.h
diffstat 1 files changed, 29 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/common.h	Fri May 23 16:04:24 2003 +0000
+++ b/common.h	Fri May 23 18:04:34 2003 +0000
@@ -1090,6 +1090,35 @@
 }
 #endif
 
+#ifdef ARCH_X86
+static inline long long rdtsc()
+{
+	long long l;
+	asm volatile(	"rdtsc\n\t"
+		: "=A" (l)
+	);
+	return l;
+}
+
+#define START_TIMER \
+static uint64_t tsum=0;\
+static int tcount=0;\
+static int tskip_count=0;\
+uint64_t tend;\
+uint64_t tstart= rdtsc();\
+
+#define STOP_TIMER(id) \
+tend= rdtsc();\
+if(tcount<2 || tend - tstart < 4*tsum/tcount){\
+    tsum+= tend - tstart;\
+    tcount++;\
+}else\
+    tskip_count++;\
+if(256*256*256*64%(tcount+tskip_count)==0){\
+    fprintf(stderr, "%Ld dezicycles in %s, %d runs, %d skips\n", tsum*10/tcount, id, tcount, tskip_count);\
+}
+#endif
+
 #define CLAMP_TO_8BIT(d) ((d > 0xff) ? 0xff : (d < 0) ? 0 : d)
 
 /* avoid usage of various functions */