ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/liblzf/bench.c
Revision: 1.9
Committed: Thu Dec 18 16:05:14 2008 UTC (15 years, 4 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.8: +8 -3 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <stdio.h>
2 #include <assert.h>
3 #include <string.h>
4 #include <time.h>
5 #include <sys/time.h>
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <sys/ioctl.h>
9 #include <sys/stat.h>
10 #include <math.h>
11 #include <signal.h>
12 #include <X11/Xlib.h>
13
14 #include "lzf.h"
15 //#include "fastlz.c"
16
17 typedef unsigned long tval;
18 typedef unsigned long long stamp64;
19
20 extern inline tval stamp(void)
21 {
22 tval tsc;
23 asm volatile("rdtsc" : "=a" (tsc) : : "edx");
24 return tsc;
25 }
26
27 extern inline tval measure(tval t)
28 {
29 tval tsc;
30 asm volatile("rdtsc" : "=a" (tsc) : : "edx");
31 if (tsc>t)
32 return tsc-t;
33 else
34 return t-tsc;
35 }
36
37 static void sigu (int signum)
38 {
39 }
40
41 int eventfd(unsigned int,int);
42
43 #define DSIZE 2821120
44
45 unsigned char data[DSIZE], data2[DSIZE*2], data3[DSIZE*2];
46
47 int main(void)
48 {
49 tval s;
50 tval si[1000];
51 int i, l, j;
52 int min = 1<<30;
53 int lp;
54 char buf[8192];
55 int p[2];
56 int evfd = eventfd (0, 0);
57 long ctr = 1;
58 struct stat sbuf;
59
60 pipe (p);
61
62 FILE *f = fopen ("data", "r");
63 fread (data, DSIZE, 1, f);
64 fclose (f);
65
66 signal (SIGURG, sigu);
67
68 for (lp = 0; lp < 100000; lp++) {
69 s=stamp();
70
71 //snprintf (buf, 64, "<1.%llx>", (unsigned long long)0xa234567812ULL);
72 //getpgrp();
73 //kill (0, SIGURG);
74 //write (evfd, &ctr, 8);
75 //read (evfd, &ctr, 8);
76 //write (p[1], &buf, 1);
77 //read (p[0], &buf, 4);
78 //stat ("/etc/passwd", &sbuf);
79 free(malloc(8*1024*1024));
80
81 si[0]=measure(s);
82
83 //j = lzf_decompress (data2, l, data3, DSIZE*2);
84
85 printf ("\r%10d (%d) ", si[0], l);
86 if (si[0] < min && si[0] > 0)
87 {
88 printf ("\n");
89 min = si[0];
90 }
91
92 fflush (stdout);
93
94 //assert (memcmp (data, data3, DSIZE) == 0);
95 }
96 return 0;
97 }
98
99
100