summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjosh.macdonald <jmacd@users.noreply.github.com>2007-11-07 03:48:13 +0000
committerjosh.macdonald <jmacd@users.noreply.github.com>2007-11-07 03:48:13 +0000
commit146646b3dfffa1f2bb85cc76115df700f81bf2e0 (patch)
treeb6a44dc6aee2230ef074411d364d8c04f5cf0f15
parente38166194f764c299b8f3e6798fefd1c819701ca (diff)
Adds compare_test for benchmarking xd3_forward_match, the optimized
version is not yet enabled in xdelta3.c
-rwxr-xr-xxdelta3/examples/Makefile7
-rw-r--r--xdelta3/examples/compare_test.c121
-rw-r--r--xdelta3/examples/speed_test.c20
3 files changed, 137 insertions, 11 deletions
diff --git a/xdelta3/examples/Makefile b/xdelta3/examples/Makefile
index a79d775..0e1825d 100755
--- a/xdelta3/examples/Makefile
+++ b/xdelta3/examples/Makefile
@@ -1,12 +1,12 @@
1#CFLAGS = -g -Wall -I.. -DXD3_DEBUG=1 1#CFLAGS = -g -Wall -I.. -DXD3_DEBUG=1
2CFLAGS = -O3 -pg -Wall -I.. -DXD3_DEBUG=0 2CFLAGS = -O3 -Wall -I.. -DXD3_DEBUG=0 -fno-builtin
3# -pg 3# -pg
4 4
5SOURCES = small_page_test.c encode_decode_test.c speed_test.c 5SOURCES = small_page_test.c encode_decode_test.c speed_test.c
6 6
7DEPS = ../*.h ../*.c 7DEPS = ../*.h ../*.c
8 8
9TARGETS = small_page_test encode_decode_test speed_test32 speed_test64 9TARGETS = small_page_test encode_decode_test speed_test32 speed_test64 compare_test
10 10
11all: $(TARGETS) 11all: $(TARGETS)
12 12
@@ -22,5 +22,8 @@ speed_test32: speed_test.c $(DEPS)
22speed_test64: speed_test.c $(DEPS) 22speed_test64: speed_test.c $(DEPS)
23 $(CC) $(CFLAGS) -DXD3_USE_LARGEFILE64=1 speed_test.c -o speed_test64 23 $(CC) $(CFLAGS) -DXD3_USE_LARGEFILE64=1 speed_test.c -o speed_test64
24 24
25compare_test: compare_test.c
26 $(CC) $(CFLAGS) compare_test.c -o compare_test
27
25clean: 28clean:
26 rm -f *.exe *.stackdump $(TARGETS) 29 rm -f *.exe *.stackdump $(TARGETS)
diff --git a/xdelta3/examples/compare_test.c b/xdelta3/examples/compare_test.c
new file mode 100644
index 0000000..1cc41a8
--- /dev/null
+++ b/xdelta3/examples/compare_test.c
@@ -0,0 +1,121 @@
1#include <stdio.h>
2#include <stdlib.h>
3#include <time.h>
4#include <string.h>
5#include <assert.h>
6
7#define NUM (1<<20)
8#define ITERS 100
9
10/* From wikipedia on RDTSC */
11__inline__ uint64_t rdtsc() {
12 uint32_t lo, hi;
13 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
14 return (uint64_t)hi << 32 | lo;
15}
16
17typedef int (*test_func)(const char *s1, const char *s2, int n);
18
19void run_test(const char *buf1, const char *buf2,
20 const char *name, test_func func) {
21 uint64_t start, end;
22 uint64_t accum = 0;
23 int i, x;
24
25 for (i = 0; i < ITERS; i++) {
26 start = rdtsc();
27 x = func(buf1, buf2, NUM);
28 end = rdtsc();
29 accum += end - start;
30 assert(x == NUM - 1);
31 }
32
33 accum /= ITERS;
34
35 printf("%s : %qu cycles\n", name, accum);
36}
37
38/* Build w/ -fno-builtin for this to be fast, this assumes that there
39 * is a difference at s1[n-1] */
40int memcmp_fake(const char *s1, const char *s2, int n) {
41 int x = memcmp(s1, s2, n);
42 return x < 0 ? n - 1 : n + 1;
43}
44
45#define UNALIGNED_OK 1
46static inline int
47test2(const char *s1c, const char *s2c, int n)
48{
49 int i = 0;
50#if UNALIGNED_OK
51 int nint = n / sizeof(int);
52
53 if (nint >> 3)
54 {
55 int j = 0;
56 const int *s1 = (const int*)s1c;
57 const int *s2 = (const int*)s2c;
58 int nint_8 = nint - 8;
59
60 while (i <= nint_8 &&
61 s1[i++] == s2[j++] &&
62 s1[i++] == s2[j++] &&
63 s1[i++] == s2[j++] &&
64 s1[i++] == s2[j++] &&
65 s1[i++] == s2[j++] &&
66 s1[i++] == s2[j++] &&
67 s1[i++] == s2[j++] &&
68 s1[i++] == s2[j++]) { }
69
70 i = (i - 1) * sizeof(int);
71 }
72#endif
73
74 while (i < n && s1c[i] == s2c[i])
75 {
76 i++;
77 }
78 return i;
79}
80
81static inline int
82test1(const char *s1c, const char *s2c, int n) {
83 int i = 0;
84 while (i < n && s1c[i] == s2c[i])
85 {
86 i++;
87 }
88 return i;
89}
90
91int main(/*int argc, char **argv*/) {
92 char *buf1 = malloc(NUM+1);
93 char *buf2 = malloc(NUM+1);
94 int i;
95
96 for (i = 0; i < NUM; i++) {
97 buf1[i] = buf2[i] = rand();
98 }
99
100 buf2[NUM-1]++;
101
102 printf ("ALIGNED\n");
103
104 run_test(buf1, buf2, "memcmp", &memcmp_fake);
105 run_test(buf1, buf2, "test1", &test1);
106 run_test(buf1, buf2, "test2", &test2);
107
108 for (i = 0; i < NUM; i++) {
109 buf1[i] = buf2[i+1] = rand();
110 }
111
112 buf2[NUM]++;
113
114 printf ("UNALIGNED\n");
115
116 run_test(buf1, buf2+1, "memcmp", &memcmp_fake);
117 run_test(buf1, buf2+1, "test1", &test1);
118 run_test(buf1, buf2+1, "test2", &test2);
119
120 return 0;
121}
diff --git a/xdelta3/examples/speed_test.c b/xdelta3/examples/speed_test.c
index 58e9aca..dea6621 100644
--- a/xdelta3/examples/speed_test.c
+++ b/xdelta3/examples/speed_test.c
@@ -53,22 +53,24 @@ int read_whole_file(const char *name,
53} 53}
54 54
55int main(int argc, char **argv) { 55int main(int argc, char **argv) {
56 int repeat; 56 int repeat, level;
57 char *from, *to; 57 char *from, *to;
58 uint8_t *from_buf = NULL, *to_buf = NULL, *delta_buf = NULL; 58 uint8_t *from_buf = NULL, *to_buf = NULL, *delta_buf = NULL;
59 size_t from_len, to_len, delta_alloc, delta_size = 0; 59 size_t from_len, to_len, delta_alloc, delta_size = 0;
60 long start, finish; 60 long start, finish;
61 int i, ret; 61 int i, ret;
62 int flags = XD3_COMPLEVEL_1; 62 int flags;
63 63
64 if (argc != 4) { 64 if (argc != 5) {
65 fprintf(stderr, "usage: speed_test COUNT FROM TO\n"); 65 fprintf(stderr, "usage: speed_test LEVEL COUNT FROM TO\n");
66 return 1; 66 return 1;
67 } 67 }
68 68
69 repeat = atoi(argv[1]); 69 level = atoi(argv[1]);
70 from = argv[2]; 70 repeat = atoi(argv[2]);
71 to = argv[3]; 71 from = argv[3];
72 to = argv[4];
73 flags = (level << XD3_COMPLEVEL_SHIFT) & XD3_COMPLEVEL_MASK;
72 74
73 if ((ret = read_whole_file(from, &from_buf, &from_len)) || 75 if ((ret = read_whole_file(from, &from_buf, &from_len)) ||
74 (ret = read_whole_file(to, &to_buf, &to_len))) { 76 (ret = read_whole_file(to, &to_buf, &to_len))) {
@@ -88,8 +90,8 @@ int main(int argc, char **argv) {
88 finish = get_millisecs_now(); 90 finish = get_millisecs_now();
89 91
90 fprintf(stderr, 92 fprintf(stderr,
91 "STAT: encode %3ld ms from %s to %s repeat %d %dbit delta %d\n", 93 "STAT: encode %3.2f ms from %s to %s repeat %d %dbit delta %d\n",
92 (finish - start) / repeat, from, to, repeat, sizeof (xoff_t) * 8, delta_size); 94 (double)(finish - start) / repeat, from, to, repeat, sizeof (xoff_t) * 8, delta_size);
93 95
94 ret = 0; 96 ret = 0;
95 97