ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
Revision: 1.12
Committed: Sun May 30 05:46:56 2010 UTC (13 years, 11 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.11: +9 -5 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 root 1.11 #include <sys/times.h>
7 root 1.7 #include <sys/types.h>
8     #include <sys/socket.h>
9 root 1.12 #include <sys/mman.h>
10 root 1.7 #include <sys/ioctl.h>
11 root 1.9 #include <sys/stat.h>
12 root 1.11 #include <sys/resource.h>
13 root 1.7 #include <math.h>
14 root 1.8 #include <signal.h>
15 root 1.7 #include <X11/Xlib.h>
16 root 1.1
17     #include "lzf.h"
18 root 1.4 //#include "fastlz.c"
19 root 1.1
20     typedef unsigned long tval;
21     typedef unsigned long long stamp64;
22    
23     extern inline tval stamp(void)
24     {
25     tval tsc;
26     asm volatile("rdtsc" : "=a" (tsc) : : "edx");
27     return tsc;
28     }
29    
30     extern inline tval measure(tval t)
31     {
32     tval tsc;
33     asm volatile("rdtsc" : "=a" (tsc) : : "edx");
34     if (tsc>t)
35     return tsc-t;
36     else
37     return t-tsc;
38     }
39    
40 root 1.8 static void sigu (int signum)
41     {
42     }
43    
44     int eventfd(unsigned int,int);
45    
46 root 1.4 #define DSIZE 2821120
47 root 1.1
48     unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2];
49    
50     int main(void)
51     {
52     tval s;
53     tval si[1000];
54     int i, l, j;
55     int min = 1<<30;
56 root 1.2 int lp;
57 root 1.7 char buf[8192];
58     int p[2];
59 root 1.8 int evfd = eventfd (0, 0);
60     long ctr = 1;
61 root 1.9 struct stat sbuf;
62 root 1.7
63     pipe (p);
64 root 1.1
65     FILE *f = fopen ("data", "r");
66     fread (data, DSIZE, 1, f);
67     fclose (f);
68 root 1.7
69 root 1.8 signal (SIGURG, sigu);
70    
71 root 1.11 for (lp = 0; lp < 1000000; lp++) {
72 root 1.6 s=stamp();
73 root 1.7
74 root 1.12 //struct timespec ts; clock_gettime (CLOCK_THREAD_CPUTIME_ID, &ts);
75 root 1.11 //printf ("%9ld\n", ts.tv_nsec);//D
76     //struct rusage usage; getrusage (RUSAGE_SELF, &usage);
77     //struct tms tms; times (&tms);
78    
79 root 1.8 //kill (0, SIGURG);
80     //write (evfd, &ctr, 8);
81     //read (evfd, &ctr, 8);
82 root 1.9 //write (p[1], &buf, 1);
83     //read (p[0], &buf, 4);
84     //stat ("/etc/passwd", &sbuf);
85 root 1.11 //struct timeval tv; gettimeofday (&tv, 0);
86 root 1.12 //void *x = mmap (0, 16384, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
87 root 1.10
88 root 1.12 l = lzf_compress (data, DSIZE, data2, DSIZE*2);
89     assert(l);
90    
91     j = lzf_decompress (data2, l, data3, DSIZE*2);
92     assert (j == DSIZE);
93 root 1.7
94 root 1.6 si[0]=measure(s);
95 root 1.7
96 root 1.12 assert (!memcmp (data, data3, DSIZE));
97 root 1.1
98     printf ("\r%10d (%d) ", si[0], l);
99     if (si[0] < min && si[0] > 0)
100     {
101     printf ("\n");
102     min = si[0];
103     }
104    
105     fflush (stdout);
106    
107 root 1.7 //assert (memcmp (data, data3, DSIZE) == 0);
108 root 1.1 }
109     return 0;
110     }
111    
112    
113