1 |
#include <stdio.h> |
2 |
#include <assert.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> |
16 |
|
17 |
#include "lzf.h" |
18 |
//#include "fastlz.c" |
19 |
|
20 |
typedef unsigned long tval; |
21 |
typedef unsigned long long stamp64; |
22 |
|
23 |
extern inline tval stamp(void) |
24 |
{ |
25 |
tval tsc; |
26 |
asm volatile("rdtsc" : "=a" (tsc) : : "edx"); |
27 |
return tsc; |
28 |
} |
29 |
|
30 |
extern inline tval measure(tval t) |
31 |
{ |
32 |
tval tsc; |
33 |
asm volatile("rdtsc" : "=a" (tsc) : : "edx"); |
34 |
if (tsc>t) |
35 |
return tsc-t; |
36 |
else |
37 |
return t-tsc; |
38 |
} |
39 |
|
40 |
static void sigu (int signum) |
41 |
{ |
42 |
} |
43 |
|
44 |
int eventfd(unsigned int,int); |
45 |
|
46 |
#define DSIZE 2821120 |
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 |
int evfd = eventfd (0, 0); |
60 |
long ctr = 1; |
61 |
struct stat sbuf; |
62 |
|
63 |
pipe (p); |
64 |
|
65 |
FILE *f = fopen ("data", "r"); |
66 |
fread (data, DSIZE, 1, f); |
67 |
fclose (f); |
68 |
|
69 |
signal (SIGURG, sigu); |
70 |
|
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 |
|
88 |
l = lzf_compress (data, DSIZE, data2, DSIZE*2); |
89 |
assert(l); |
90 |
|
91 |
j = lzf_decompress (data2, l, data3, DSIZE*2); |
92 |
assert (j == DSIZE); |
93 |
|
94 |
si[0]=measure(s); |
95 |
|
96 |
assert (!memcmp (data, data3, DSIZE)); |
97 |
|
98 |
printf ("\r%10d (%d) ", si[0], l); |
99 |
if (si[0] < min && si[0] > 0) |
100 |
{ |
101 |
printf ("\n"); |
102 |
min = si[0]; |
103 |
} |
104 |
|
105 |
fflush (stdout); |
106 |
|
107 |
//assert (memcmp (data, data3, DSIZE) == 0); |
108 |
} |
109 |
return 0; |
110 |
} |
111 |
|
112 |
|
113 |
|