ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
Revision: 1.4
Committed: Tue Nov 13 10:48:02 2007 UTC (16 years, 6 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.3: +4 -2 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <stdio.h>
2 #include <assert.h>
3 #include <string.h>
4
5 #include "lzf.h"
6 //#include "fastlz.c"
7
8 typedef unsigned long tval;
9 typedef unsigned long long stamp64;
10
11 extern inline tval stamp(void)
12 {
13 tval tsc;
14 asm volatile("rdtsc" : "=a" (tsc) : : "edx");
15 return tsc;
16 }
17
18 extern inline tval measure(tval t)
19 {
20 tval tsc;
21 asm volatile("rdtsc" : "=a" (tsc) : : "edx");
22 if (tsc>t)
23 return tsc-t;
24 else
25 return t-tsc;
26 }
27
28 #define DSIZE 2821120
29
30 unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2];
31
32 int main(void)
33 {
34 tval s;
35 tval si[1000];
36 int i, l, j;
37 int min = 1<<30;
38 int lp;
39
40 FILE *f = fopen ("data", "r");
41 fread (data, DSIZE, 1, f);
42 fclose (f);
43
44 for (lp = 0; lp < 1000; lp++) {
45 s=stamp();
46 l = lzf_compress (data, DSIZE, data2, DSIZE*2);
47 //l = fastlz_compress_level (1, data, DSIZE, data2);
48 si[0]=measure(s);
49 j = lzf_decompress (data2, l, data3, DSIZE*2);
50
51 printf ("\r%10d (%d) ", si[0], l);
52 if (si[0] < min && si[0] > 0)
53 {
54 printf ("\n");
55 min = si[0];
56 }
57
58 fflush (stdout);
59
60 assert (memcmp (data, data3, DSIZE) == 0);
61 }
62 return 0;
63 }
64
65
66