"Fossies" - the Fresh Open Source Software Archive

Member "xdelta3-3.0.11/examples/speed_test.c" (24 Mar 2015, 1834 Bytes) of package /linux/misc/xdelta3-3.0.11.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /* Copyright (C) 2007 Josh MacDonald */
    2 
    3 #include "test.h"
    4 
    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,
    8          int flags) {
    9   usize_t delta_size;
   10   int ret = xd3_encode_memory(to_buf, to_len, from_buf, from_len,
   11                   delta_buf, &delta_size, delta_alloc, flags);
   12   if (ret != 0) {
   13     fprintf(stderr, "encode failure: %d: %s\n", ret, xd3_strerror(ret));
   14     abort();
   15   }
   16   return delta_size;
   17 }
   18 
   19 int main(int argc, char **argv) {
   20   int repeat, level;
   21   char *from, *to;
   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;
   24   long start, finish;
   25   int i, ret;
   26   int flags;
   27 
   28   if (argc != 5) {
   29     fprintf(stderr, "usage: speed_test LEVEL COUNT FROM TO\n");
   30     return 1;
   31   }
   32 
   33   level = atoi(argv[1]);
   34   repeat = atoi(argv[2]);
   35   from = argv[3];
   36   to = argv[4];
   37   flags = (level << XD3_COMPLEVEL_SHIFT) & XD3_COMPLEVEL_MASK;
   38 
   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");
   43     goto exit;
   44   }
   45 
   46   delta_alloc = to_len * 11 / 10;
   47   delta_buf = main_malloc(delta_alloc);
   48 
   49   start = get_millisecs_now();
   50 
   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);
   54   }
   55 
   56   finish = get_millisecs_now();
   57 
   58   fprintf(stderr,
   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);
   61 
   62   ret = 0;
   63 
   64   if (0) {
   65   exit:
   66     ret = 1;
   67   }
   68     
   69   main_free(to_buf);
   70   main_free(from_buf);
   71   main_free(delta_buf);
   72   return ret;
   73 }