ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
Revision: 1.2
Committed: Sun May 30 19:27:12 2004 UTC (20 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.1: +2 -1 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
7 typedef unsigned long tval;
8 typedef unsigned long long stamp64;
9
10 extern inline tval stamp(void)
11 {
12 tval tsc;
13 asm volatile("rdtsc" : "=a" (tsc) : : "edx");
14 return tsc;
15 }
16
17 extern inline tval measure(tval t)
18 {
19 tval tsc;
20 asm volatile("rdtsc" : "=a" (tsc) : : "edx");
21 if (tsc>t)
22 return tsc-t;
23 else
24 return t-tsc;
25 }
26
27 #define DSIZE 1000000
28
29 unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2];
30
31 int main(void)
32 {
33 tval s;
34 tval si[1000];
35 int i, l, j;
36 int min = 1<<30;
37 int lp;
38
39 FILE *f = fopen ("data", "r");
40 fread (data, DSIZE, 1, f);
41 fclose (f);
42
43 for (lp = 0; lp < 100; lp++) {
44 s=stamp();
45 l = lzf_compress (data, DSIZE, data2, DSIZE*2);
46 j = lzf_decompress (data2, l, data3, DSIZE*2);
47 si[0]=measure(s);
48
49 printf ("\r%10d (%d) ", si[0], l);
50 if (si[0] < min && si[0] > 0)
51 {
52 printf ("\n");
53 min = si[0];
54 }
55
56 fflush (stdout);
57
58 assert (memcmp (data, data3, DSIZE) == 0);
59 }
60 return 0;
61 }
62
63
64