ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
Revision: 1.9
Committed: Thu Dec 18 16:05:14 2008 UTC (15 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.8: +8 -3 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 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     //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     free(malloc(8*1024*1024));
80 root 1.7
81 root 1.6 si[0]=measure(s);
82 root 1.7
83     //j = lzf_decompress (data2, l, data3, DSIZE*2);
84 root 1.1
85     printf ("\r%10d (%d) ", si[0], l);
86     if (si[0] < min && si[0] > 0)
87     {
88     printf ("\n");
89     min = si[0];
90     }
91    
92     fflush (stdout);
93    
94 root 1.7 //assert (memcmp (data, data3, DSIZE) == 0);
95 root 1.1 }
96     return 0;
97     }
98    
99    
100