ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
(Generate patch)

Comparing liblzf/bench.c (file contents):
Revision 1.2 by root, Sun May 30 19:27:12 2004 UTC vs.
Revision 1.15 by root, Thu Feb 16 05:43:19 2012 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines