ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
Revision: 1.14
Committed: Sun Mar 27 23:53:23 2011 UTC (13 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.13: +1 -0 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <stdio.h>
2 #include <unistd.h>
3 #include <assert.h>
4 #include <string.h>
5 #include <time.h>
6 #include <sys/time.h>
7 #include <sys/times.h>
8 #include <sys/types.h>
9 #include <sys/socket.h>
10 #include <sys/mman.h>
11 #include <sys/ioctl.h>
12 #include <sys/stat.h>
13 #include <sys/resource.h>
14 #include <math.h>
15 #include <signal.h>
16 #include <X11/Xlib.h>
17
18 #include "lzf.h"
19 //#include "fastlz.c"
20
21 typedef unsigned long tval;
22 typedef unsigned long long stamp64;
23
24 extern inline tval stamp(void)
25 {
26 tval tsc;
27 asm volatile("rdtsc" : "=a" (tsc) : : "edx");
28 return tsc;
29 }
30
31 extern inline tval measure(tval t)
32 {
33 tval tsc;
34 asm volatile("rdtsc" : "=a" (tsc) : : "edx");
35 if (tsc>t)
36 return tsc-t;
37 else
38 return t-tsc;
39 }
40
41 static void sigu (int signum)
42 {
43 }
44
45 #define DSIZE 2821120
46 #define DSIZE 32768
47
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 int lp;
57 char buf[8192];
58 int p[2];
59 long ctr = 1;
60 struct stat sbuf;
61
62 pipe (p);
63
64 FILE *f = fopen ("data", "r");
65 fread (data, DSIZE, 1, f);
66 fclose (f);
67
68 signal (SIGURG, sigu);
69
70 for (lp = 0; lp < 1000000; lp++) {
71 s=stamp();
72
73 //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 //kill (0, SIGURG);
79 //write (evfd, &ctr, 8);
80 //read (evfd, &ctr, 8);
81 //write (p[1], &buf, 1);
82 //read (p[0], &buf, 4);
83 //stat ("/etc/passwd", &sbuf);
84 //struct timeval tv; gettimeofday (&tv, 0);
85 //void *x = mmap (0, 16384, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
86
87 l = lzf_compress (data, DSIZE, data2, DSIZE*2);
88 assert(l);
89
90 j = lzf_decompress (data2, l, data3, DSIZE*2);
91 assert (j == DSIZE);
92
93 si[0]=measure(s);
94
95 assert (!memcmp (data, data3, DSIZE));
96
97 printf ("\r%10d (%d) ", si[0], l);
98 if (si[0] < min && si[0] > 0)
99 {
100 printf ("\n");
101 min = si[0];
102 }
103
104 fflush (stdout);
105
106 //assert (memcmp (data, data3, DSIZE) == 0);
107 }
108 return 0;
109 }
110
111
112