1
/* Copyright (C) 2007 Josh MacDonald */
8
usize_t bench_speed(const uint8_t *from_buf, const size_t from_len,
9
const uint8_t *to_buf, const size_t to_len,
10
uint8_t *delta_buf, const size_t delta_alloc,
13
int ret = xd3_encode_memory(to_buf, to_len, from_buf, from_len,
14
delta_buf, &delta_size, delta_alloc, flags);
16
fprintf(stderr, "encode failure: %d: %s\n", ret, xd3_strerror(ret));
22
int read_whole_file(const char *name,
29
main_file_init(&file);
31
ret = main_file_open(&file, name, XO_READ);
35
ret = main_file_stat(&file, &len, 1);
40
(*buf_len) = (size_t)len;
41
(*buf_ptr) = main_malloc(*buf_len);
42
ret = main_file_read(&file, *buf_ptr, *buf_len, &nread,
44
if (ret == 0 && *buf_len == nread) {
47
fprintf(stderr, "invalid read\n");
51
main_file_cleanup(&file);
55
int main(int argc, char **argv) {
58
uint8_t *from_buf = NULL, *to_buf = NULL, *delta_buf = NULL;
59
size_t from_len, to_len, delta_alloc, delta_size = 0;
65
fprintf(stderr, "usage: speed_test LEVEL COUNT FROM TO\n");
69
level = atoi(argv[1]);
70
repeat = atoi(argv[2]);
73
flags = (level << XD3_COMPLEVEL_SHIFT) & XD3_COMPLEVEL_MASK;
75
if ((ret = read_whole_file(from, &from_buf, &from_len)) ||
76
(ret = read_whole_file(to, &to_buf, &to_len))) {
77
fprintf(stderr, "read_whole_file error\n");
81
delta_alloc = to_len * 11 / 10;
82
delta_buf = main_malloc(delta_alloc);
84
start = get_millisecs_now();
86
for (i = 0; i < repeat; ++i) {
87
delta_size = bench_speed(from_buf, from_len, to_buf, to_len, delta_buf, delta_alloc, flags);
90
finish = get_millisecs_now();
93
"STAT: encode %3.2f ms from %s to %s repeat %d %dbit delta %d\n",
94
(double)(finish - start) / repeat, from, to, repeat, sizeof (xoff_t) * 8, delta_size);
105
main_free(delta_buf);