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