ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
Revision: 1.7
Committed: Fri Feb 8 13:20:26 2008 UTC (16 years, 3 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.6: +21 -6 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 #include <stdio.h>
2     #include <assert.h>
3     #include <string.h>
4 root 1.7 #include <time.h>
5     #include <sys/time.h>
6     #include <sys/types.h>
7     #include <sys/socket.h>
8     #include <sys/ioctl.h>
9     #include <math.h>
10     #include <X11/Xlib.h>
11 root 1.1
12     #include "lzf.h"
13 root 1.4 //#include "fastlz.c"
14 root 1.1
15     typedef unsigned long tval;
16     typedef unsigned long long stamp64;
17    
18     extern inline tval stamp(void)
19     {
20     tval tsc;
21     asm volatile("rdtsc" : "=a" (tsc) : : "edx");
22     return tsc;
23     }
24    
25     extern inline tval measure(tval t)
26     {
27     tval tsc;
28     asm volatile("rdtsc" : "=a" (tsc) : : "edx");
29     if (tsc>t)
30     return tsc-t;
31     else
32     return t-tsc;
33     }
34    
35 root 1.4 #define DSIZE 2821120
36 root 1.1
37     unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2];
38    
39     int main(void)
40     {
41     tval s;
42     tval si[1000];
43     int i, l, j;
44     int min = 1<<30;
45 root 1.2 int lp;
46 root 1.7 char buf[8192];
47     int p[2];
48    
49     pipe (p);
50 root 1.1
51     FILE *f = fopen ("data", "r");
52     fread (data, DSIZE, 1, f);
53     fclose (f);
54 root 1.7
55     for (lp = 0; lp < 100000; lp++) {
56 root 1.6 s=stamp();
57 root 1.7
58     kill (0, 23);
59     // write (p[1], &p, 1);
60     // read (p[1], &i, 4);
61    
62 root 1.6 si[0]=measure(s);
63 root 1.7
64     //j = lzf_decompress (data2, l, data3, DSIZE*2);
65 root 1.1
66     printf ("\r%10d (%d) ", si[0], l);
67     if (si[0] < min && si[0] > 0)
68     {
69     printf ("\n");
70     min = si[0];
71     }
72    
73     fflush (stdout);
74    
75 root 1.7 //assert (memcmp (data, data3, DSIZE) == 0);
76 root 1.1 }
77     return 0;
78     }
79    
80    
81