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

Comparing liblzf/bench.c (file contents):
Revision 1.3 by root, Tue Mar 8 19:59:52 2005 UTC vs.
Revision 1.12 by root, Sun May 30 05:46:56 2010 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines