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