1 |
#include <stdio.h> |
2 |
#include <assert.h> |
3 |
#include <string.h> |
4 |
#include <time.h> |
5 |
#include <sys/time.h> |
6 |
#include <sys/types.h> |
7 |
#include <sys/socket.h> |
8 |
#include <sys/ioctl.h> |
9 |
#include <math.h> |
10 |
#include <signal.h> |
11 |
#include <X11/Xlib.h> |
12 |
|
13 |
#include "lzf.h" |
14 |
//#include "fastlz.c" |
15 |
|
16 |
typedef unsigned long tval; |
17 |
typedef unsigned long long stamp64; |
18 |
|
19 |
extern inline tval stamp(void) |
20 |
{ |
21 |
tval tsc; |
22 |
asm volatile("rdtsc" : "=a" (tsc) : : "edx"); |
23 |
return tsc; |
24 |
} |
25 |
|
26 |
extern inline tval measure(tval t) |
27 |
{ |
28 |
tval tsc; |
29 |
asm volatile("rdtsc" : "=a" (tsc) : : "edx"); |
30 |
if (tsc>t) |
31 |
return tsc-t; |
32 |
else |
33 |
return t-tsc; |
34 |
} |
35 |
|
36 |
static void sigu (int signum) |
37 |
{ |
38 |
} |
39 |
|
40 |
int eventfd(unsigned int,int); |
41 |
|
42 |
#define DSIZE 2821120 |
43 |
|
44 |
unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2]; |
45 |
|
46 |
int main(void) |
47 |
{ |
48 |
tval s; |
49 |
tval si[1000]; |
50 |
int i, l, j; |
51 |
int min = 1<<30; |
52 |
int lp; |
53 |
char buf[8192]; |
54 |
int p[2]; |
55 |
int evfd = eventfd (0, 0); |
56 |
long ctr = 1; |
57 |
|
58 |
pipe (p); |
59 |
|
60 |
FILE *f = fopen ("data", "r"); |
61 |
fread (data, DSIZE, 1, f); |
62 |
fclose (f); |
63 |
|
64 |
signal (SIGURG, sigu); |
65 |
|
66 |
for (lp = 0; lp < 100000; lp++) { |
67 |
s=stamp(); |
68 |
|
69 |
snprintf (buf, 64, "<1.%llx>", (unsigned long long)0xa234567812ULL); |
70 |
//kill (0, SIGURG); |
71 |
//write (evfd, &ctr, 8); |
72 |
//read (evfd, &ctr, 8); |
73 |
// write (p[1], &buf, 1); |
74 |
// read (p[0], &buf, 4); |
75 |
|
76 |
si[0]=measure(s); |
77 |
|
78 |
//j = lzf_decompress (data2, l, data3, DSIZE*2); |
79 |
|
80 |
printf ("\r%10d (%d) ", si[0], l); |
81 |
if (si[0] < min && si[0] > 0) |
82 |
{ |
83 |
printf ("\n"); |
84 |
min = si[0]; |
85 |
} |
86 |
|
87 |
fflush (stdout); |
88 |
|
89 |
//assert (memcmp (data, data3, DSIZE) == 0); |
90 |
} |
91 |
return 0; |
92 |
} |
93 |
|
94 |
|
95 |
|