1 /* Copyright (C) 2007 Josh MacDonald */
5 usize_t bench_speed(const uint8_t *from_buf, const size_t from_len,
6 const uint8_t *to_buf, const size_t to_len,
7 uint8_t *delta_buf, const size_t delta_alloc,
10 int ret = xd3_encode_memory(to_buf, to_len, from_buf, from_len,
11 delta_buf, &delta_size, delta_alloc, flags);
13 fprintf(stderr, "encode failure: %d: %s\n", ret, xd3_strerror(ret));
19 int main(int argc, char **argv) {
22 uint8_t *from_buf = NULL, *to_buf = NULL, *delta_buf = NULL;
23 size_t from_len = 0, to_len, delta_alloc, delta_size = 0;
29 fprintf(stderr, "usage: speed_test LEVEL COUNT FROM TO\n");
33 level = atoi(argv[1]);
34 repeat = atoi(argv[2]);
37 flags = (level << XD3_COMPLEVEL_SHIFT) & XD3_COMPLEVEL_MASK;
39 if ((strcmp(from, "null") != 0 &&
40 (ret = read_whole_file(from, &from_buf, &from_len))) ||
41 (ret = read_whole_file(to, &to_buf, &to_len))) {
42 fprintf(stderr, "read_whole_file error\n");
46 delta_alloc = to_len * 11 / 10;
47 delta_buf = main_malloc(delta_alloc);
49 start = get_millisecs_now();
51 for (i = 0; i < repeat; ++i) {
52 delta_size = bench_speed(from_buf, from_len,
53 to_buf, to_len, delta_buf, delta_alloc, flags);
56 finish = get_millisecs_now();
59 "STAT: encode %3.2f ms from %s to %s repeat %d %zdbit delta %zd\n",
60 (double)(finish - start) / repeat, from, to, repeat, sizeof (xoff_t) * 8, delta_size);