1 |
#include <stdio.h> |
2 |
#include <assert.h> |
3 |
#include <string.h> |
4 |
|
5 |
#include "lzf.h" |
6 |
|
7 |
typedef unsigned long tval; |
8 |
typedef unsigned long long stamp64; |
9 |
|
10 |
extern inline tval stamp(void) |
11 |
{ |
12 |
tval tsc; |
13 |
asm volatile("rdtsc" : "=a" (tsc) : : "edx"); |
14 |
return tsc; |
15 |
} |
16 |
|
17 |
extern inline tval measure(tval t) |
18 |
{ |
19 |
tval tsc; |
20 |
asm volatile("rdtsc" : "=a" (tsc) : : "edx"); |
21 |
if (tsc>t) |
22 |
return tsc-t; |
23 |
else |
24 |
return t-tsc; |
25 |
} |
26 |
|
27 |
#define DSIZE 1000000 |
28 |
|
29 |
unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2]; |
30 |
|
31 |
int main(void) |
32 |
{ |
33 |
tval s; |
34 |
tval si[1000]; |
35 |
int i, l, j; |
36 |
int min = 1<<30; |
37 |
|
38 |
FILE *f = fopen ("data", "r"); |
39 |
fread (data, DSIZE, 1, f); |
40 |
fclose (f); |
41 |
|
42 |
for(;;) { |
43 |
s=stamp(); |
44 |
l = lzf_compress (data, DSIZE, data2, DSIZE*2); |
45 |
j = lzf_decompress (data2, l, data3, DSIZE*2); |
46 |
si[0]=measure(s); |
47 |
|
48 |
printf ("\r%10d (%d) ", si[0], l); |
49 |
if (si[0] < min && si[0] > 0) |
50 |
{ |
51 |
printf ("\n"); |
52 |
min = si[0]; |
53 |
} |
54 |
|
55 |
fflush (stdout); |
56 |
|
57 |
assert (memcmp (data, data3, DSIZE) == 0); |
58 |
} |
59 |
return 0; |
60 |
} |
61 |
|
62 |
|
63 |
|