ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
Revision: 1.10
Committed: Fri May 1 00:30:53 2009 UTC (15 years ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: rel-3_5
Changes since 1.9: +8 -3 lines
Log Message:
3.5

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 root 1.9 #include <sys/stat.h>
10 root 1.7 #include <math.h>
11 root 1.8 #include <signal.h>
12 root 1.7 #include <X11/Xlib.h>
13 root 1.1
14     #include "lzf.h"
15 root 1.4 //#include "fastlz.c"
16 root 1.1
17     typedef unsigned long tval;
18     typedef unsigned long long stamp64;
19    
20     extern inline tval stamp(void)
21     {
22     tval tsc;
23     asm volatile("rdtsc" : "=a" (tsc) : : "edx");
24     return tsc;
25     }
26    
27     extern inline tval measure(tval t)
28     {
29     tval tsc;
30     asm volatile("rdtsc" : "=a" (tsc) : : "edx");
31     if (tsc>t)
32     return tsc-t;
33     else
34     return t-tsc;
35     }
36    
37 root 1.8 static void sigu (int signum)
38     {
39     }
40    
41     int eventfd(unsigned int,int);
42    
43 root 1.4 #define DSIZE 2821120
44 root 1.1
45     unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2];
46    
47     int main(void)
48     {
49     tval s;
50     tval si[1000];
51     int i, l, j;
52     int min = 1<<30;
53 root 1.2 int lp;
54 root 1.7 char buf[8192];
55     int p[2];
56 root 1.8 int evfd = eventfd (0, 0);
57     long ctr = 1;
58 root 1.9 struct stat sbuf;
59 root 1.7
60     pipe (p);
61 root 1.1
62     FILE *f = fopen ("data", "r");
63     fread (data, DSIZE, 1, f);
64     fclose (f);
65 root 1.7
66 root 1.8 signal (SIGURG, sigu);
67    
68 root 1.7 for (lp = 0; lp < 100000; lp++) {
69 root 1.6 s=stamp();
70 root 1.7
71 root 1.9 //snprintf (buf, 64, "<1.%llx>", (unsigned long long)0xa234567812ULL);
72 root 1.10 getpgrp();
73 root 1.8 //kill (0, SIGURG);
74     //write (evfd, &ctr, 8);
75     //read (evfd, &ctr, 8);
76 root 1.9 //write (p[1], &buf, 1);
77     //read (p[0], &buf, 4);
78     //stat ("/etc/passwd", &sbuf);
79 root 1.10 //struct timeval tv;
80     //gettimeofday (&tv, 0);
81    
82     l = lzf_compress (data, DSIZE, data2, DSIZE*2);
83     assert(l);
84 root 1.7
85 root 1.6 si[0]=measure(s);
86 root 1.7
87 root 1.10 j = lzf_decompress (data2, l, data3, DSIZE*2);
88     assert (j == DSIZE);
89 root 1.1
90     printf ("\r%10d (%d) ", si[0], l);
91     if (si[0] < min && si[0] > 0)
92     {
93     printf ("\n");
94     min = si[0];
95     }
96    
97     fflush (stdout);
98    
99 root 1.7 //assert (memcmp (data, data3, DSIZE) == 0);
100 root 1.1 }
101     return 0;
102     }
103    
104    
105