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

Comparing liblzf/bench.c (file contents):
Revision 1.11 by root, Sat Jul 18 05:59:21 2009 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>
4#include <time.h> 5#include <time.h>
5#include <sys/time.h> 6#include <sys/time.h>
6#include <sys/times.h> 7#include <sys/times.h>
7#include <sys/types.h> 8#include <sys/types.h>
8#include <sys/socket.h> 9#include <sys/socket.h>
10#include <sys/mman.h>
9#include <sys/ioctl.h> 11#include <sys/ioctl.h>
10#include <sys/stat.h> 12#include <sys/stat.h>
11#include <sys/resource.h> 13#include <sys/resource.h>
12#include <math.h> 14#include <math.h>
13#include <signal.h> 15#include <signal.h>
38 40
39static void sigu (int signum) 41static void sigu (int signum)
40{ 42{
41} 43}
42 44
43int eventfd(unsigned int,int); 45#define DSIZE 17318440
46//#define DSIZE 32768
44 47
45#define DSIZE 2821120 48#include "lzf_c_slow.c"
46 49
47unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2]; 50unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2];
48 51
49int main(void) 52int main(void)
50{ 53{
51 tval s; 54 tval s;
52 tval si[1000]; 55 tval si[1000];
53 int i, l, j; 56 int i, j, k, l;
54 int min = 1<<30; 57 int min = 1<<30;
55 int lp; 58 int lp;
56 char buf[8192]; 59 char buf[8192];
57 int p[2]; 60 int p[2];
58 int evfd = eventfd (0, 0);
59 long ctr = 1; 61 long ctr = 1;
60 struct stat sbuf; 62 struct stat sbuf;
61 63
62 pipe (p); 64 pipe (p);
63 65
68 signal (SIGURG, sigu); 70 signal (SIGURG, sigu);
69 71
70 for (lp = 0; lp < 1000000; lp++) { 72 for (lp = 0; lp < 1000000; lp++) {
71 s=stamp(); 73 s=stamp();
72 74
73 struct timespec ts; clock_gettime (CLOCK_THREAD_CPUTIME_ID, &ts); 75 //struct timespec ts; clock_gettime (CLOCK_THREAD_CPUTIME_ID, &ts);
74 //printf ("%9ld\n", ts.tv_nsec);//D 76 //printf ("%9ld\n", ts.tv_nsec);//D
75 //struct rusage usage; getrusage (RUSAGE_SELF, &usage); 77 //struct rusage usage; getrusage (RUSAGE_SELF, &usage);
76 //struct tms tms; times (&tms); 78 //struct tms tms; times (&tms);
77 79
78 //kill (0, SIGURG); 80 //kill (0, SIGURG);
80 //read (evfd, &ctr, 8); 82 //read (evfd, &ctr, 8);
81 //write (p[1], &buf, 1); 83 //write (p[1], &buf, 1);
82 //read (p[0], &buf, 4); 84 //read (p[0], &buf, 4);
83 //stat ("/etc/passwd", &sbuf); 85 //stat ("/etc/passwd", &sbuf);
84 //struct timeval tv; gettimeofday (&tv, 0); 86 //struct timeval tv; gettimeofday (&tv, 0);
87 //void *x = mmap (0, 16384, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE,-1,0);
85 88
86 //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]);
87 //assert(l); 92 assert(l);
93
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);
88 98
89 si[0]=measure(s); 99 si[0]=measure(s);
90 100
91 //j = lzf_decompress (data2, l, data3, DSIZE*2); 101 assert (!memcmp (data, data3, DSIZE));
92 //assert (j == DSIZE);
93 102
94 printf ("\r%10d (%d) ", si[0], l); 103 printf ("\r%10d (%d) ", si[0], l);
95 if (si[0] < min && si[0] > 0) 104 if (si[0] < min && si[0] > 0)
96 { 105 {
97 printf ("\n"); 106 printf ("\n");

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines