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