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