ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
Revision: 1.11
Committed: Sat Jul 18 05:59:21 2009 UTC (14 years, 10 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.10: +13 -9 lines
Log Message:
riddify us of meta.yml garbage in manifest

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