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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <math.h>
#include <signal.h>
#include <X11/Xlib.h>
#include "lzf.h"
//#include "fastlz.c"
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;
}
static void sigu (int signum)
{
}
int eventfd(unsigned int,int);
#define DSIZE 2821120
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;
char buf[8192];
int p[2];
int evfd = eventfd (0, 0);
long ctr = 1;
struct stat sbuf;
pipe (p);
FILE *f = fopen ("data", "r");
fread (data, DSIZE, 1, f);
fclose (f);
signal (SIGURG, sigu);
for (lp = 0; lp < 100000; lp++) {
s=stamp();
//snprintf (buf, 64, "<1.%llx>", (unsigned long long)0xa234567812ULL);
getpgrp();
//kill (0, SIGURG);
//write (evfd, &ctr, 8);
//read (evfd, &ctr, 8);
//write (p[1], &buf, 1);
//read (p[0], &buf, 4);
//stat ("/etc/passwd", &sbuf);
//struct timeval tv;
//gettimeofday (&tv, 0);
l = lzf_compress (data, DSIZE, data2, DSIZE*2);
assert(l);
si[0]=measure(s);
j = lzf_decompress (data2, l, data3, DSIZE*2);
assert (j == DSIZE);
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;
}
|