| 1 |
root |
1.1 |
#include <stdio.h> |
| 2 |
root |
1.13 |
#include <unistd.h> |
| 3 |
root |
1.1 |
#include <assert.h> |
| 4 |
|
|
#include <string.h> |
| 5 |
root |
1.7 |
#include <time.h> |
| 6 |
|
|
#include <sys/time.h> |
| 7 |
root |
1.11 |
#include <sys/times.h> |
| 8 |
root |
1.7 |
#include <sys/types.h> |
| 9 |
|
|
#include <sys/socket.h> |
| 10 |
root |
1.12 |
#include <sys/mman.h> |
| 11 |
root |
1.7 |
#include <sys/ioctl.h> |
| 12 |
root |
1.9 |
#include <sys/stat.h> |
| 13 |
root |
1.11 |
#include <sys/resource.h> |
| 14 |
root |
1.7 |
#include <math.h> |
| 15 |
root |
1.8 |
#include <signal.h> |
| 16 |
root |
1.7 |
#include <X11/Xlib.h> |
| 17 |
root |
1.1 |
|
| 18 |
|
|
#include "lzf.h" |
| 19 |
root |
1.4 |
//#include "fastlz.c" |
| 20 |
root |
1.1 |
|
| 21 |
|
|
typedef unsigned long tval; |
| 22 |
|
|
typedef unsigned long long stamp64; |
| 23 |
|
|
|
| 24 |
|
|
extern inline tval stamp(void) |
| 25 |
|
|
{ |
| 26 |
|
|
tval tsc; |
| 27 |
|
|
asm volatile("rdtsc" : "=a" (tsc) : : "edx"); |
| 28 |
|
|
return tsc; |
| 29 |
|
|
} |
| 30 |
|
|
|
| 31 |
|
|
extern inline tval measure(tval t) |
| 32 |
|
|
{ |
| 33 |
|
|
tval tsc; |
| 34 |
|
|
asm volatile("rdtsc" : "=a" (tsc) : : "edx"); |
| 35 |
|
|
if (tsc>t) |
| 36 |
|
|
return tsc-t; |
| 37 |
|
|
else |
| 38 |
|
|
return t-tsc; |
| 39 |
|
|
} |
| 40 |
|
|
|
| 41 |
root |
1.8 |
static void sigu (int signum) |
| 42 |
|
|
{ |
| 43 |
|
|
} |
| 44 |
|
|
|
| 45 |
root |
1.15 |
#define DSIZE 17318440 |
| 46 |
|
|
//#define DSIZE 32768 |
| 47 |
|
|
|
| 48 |
|
|
#include "lzf_c_slow.c" |
| 49 |
root |
1.1 |
|
| 50 |
|
|
unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2]; |
| 51 |
|
|
|
| 52 |
|
|
int main(void) |
| 53 |
|
|
{ |
| 54 |
|
|
tval s; |
| 55 |
|
|
tval si[1000]; |
| 56 |
root |
1.15 |
int i, j, k, l; |
| 57 |
root |
1.1 |
int min = 1<<30; |
| 58 |
root |
1.2 |
int lp; |
| 59 |
root |
1.7 |
char buf[8192]; |
| 60 |
|
|
int p[2]; |
| 61 |
root |
1.8 |
long ctr = 1; |
| 62 |
root |
1.9 |
struct stat sbuf; |
| 63 |
root |
1.7 |
|
| 64 |
|
|
pipe (p); |
| 65 |
root |
1.1 |
|
| 66 |
|
|
FILE *f = fopen ("data", "r"); |
| 67 |
|
|
fread (data, DSIZE, 1, f); |
| 68 |
|
|
fclose (f); |
| 69 |
root |
1.7 |
|
| 70 |
root |
1.8 |
signal (SIGURG, sigu); |
| 71 |
|
|
|
| 72 |
root |
1.11 |
for (lp = 0; lp < 1000000; lp++) { |
| 73 |
root |
1.6 |
s=stamp(); |
| 74 |
root |
1.7 |
|
| 75 |
root |
1.12 |
//struct timespec ts; clock_gettime (CLOCK_THREAD_CPUTIME_ID, &ts); |
| 76 |
root |
1.11 |
//printf ("%9ld\n", ts.tv_nsec);//D |
| 77 |
|
|
//struct rusage usage; getrusage (RUSAGE_SELF, &usage); |
| 78 |
|
|
//struct tms tms; times (&tms); |
| 79 |
|
|
|
| 80 |
root |
1.8 |
//kill (0, SIGURG); |
| 81 |
|
|
//write (evfd, &ctr, 8); |
| 82 |
|
|
//read (evfd, &ctr, 8); |
| 83 |
root |
1.9 |
//write (p[1], &buf, 1); |
| 84 |
|
|
//read (p[0], &buf, 4); |
| 85 |
|
|
//stat ("/etc/passwd", &sbuf); |
| 86 |
root |
1.11 |
//struct timeval tv; gettimeofday (&tv, 0); |
| 87 |
root |
1.12 |
//void *x = mmap (0, 16384, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE,-1,0); |
| 88 |
root |
1.10 |
|
| 89 |
root |
1.15 |
l = lzf_compress_slow (data, DSIZE, data2, DSIZE*2); |
| 90 |
|
|
//for (k = 0; k < l; ++k) |
| 91 |
|
|
//printf ("1 %2d: %02x\n", k, data2[k]); |
| 92 |
root |
1.12 |
assert(l); |
| 93 |
|
|
|
| 94 |
|
|
j = lzf_decompress (data2, l, data3, DSIZE*2); |
| 95 |
root |
1.15 |
//for (k = 0; k < j; ++k) |
| 96 |
|
|
//printf ("2 %2d: %02x\n", k, data3[k]); |
| 97 |
root |
1.12 |
assert (j == DSIZE); |
| 98 |
root |
1.7 |
|
| 99 |
root |
1.6 |
si[0]=measure(s); |
| 100 |
root |
1.7 |
|
| 101 |
root |
1.12 |
assert (!memcmp (data, data3, DSIZE)); |
| 102 |
root |
1.1 |
|
| 103 |
|
|
printf ("\r%10d (%d) ", si[0], l); |
| 104 |
|
|
if (si[0] < min && si[0] > 0) |
| 105 |
|
|
{ |
| 106 |
|
|
printf ("\n"); |
| 107 |
|
|
min = si[0]; |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
fflush (stdout); |
| 111 |
|
|
|
| 112 |
root |
1.7 |
//assert (memcmp (data, data3, DSIZE) == 0); |
| 113 |
root |
1.1 |
} |
| 114 |
|
|
return 0; |
| 115 |
|
|
} |
| 116 |
|
|
|
| 117 |
|
|
|
| 118 |
|
|
|