Skip to content

Commit f73ee44

Browse files
committed
Add test to benchmark performance of checksum computation.
* subversion/tests/libsvn_subr/checksum-test.c (do_bench_test): New function that runs benchmarking test for a specific configuration of checksum algorithm and blocksize. (test_checksum_performance): New test. (test_funcs): Run new test. git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1930929 13f79535-47bb-0310-9956-ffa450edef68
1 parent 05f68ba commit f73ee44

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

subversion/tests/libsvn_subr/checksum-test.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,71 @@ test_checksummed_stream_reset(apr_pool_t *pool)
364364
return SVN_NO_ERROR;
365365
}
366366

367+
static svn_error_t *
368+
do_bench_test(apr_size_t blocksize, svn_checksum_kind_t kind, apr_pool_t *pool)
369+
{
370+
svn_checksum_ctx_t *ctx = svn_checksum_ctx_create(kind, pool);
371+
svn_checksum_t *checksum;
372+
char *buf = apr_palloc(pool, blocksize);
373+
apr_time_t start;
374+
apr_size_t count = 0;
375+
apr_uint32_t seed = 67;
376+
apr_size_t i;
377+
378+
for (i = 0; i < blocksize; i++)
379+
buf[i] = (char)svn_test_rand(&seed);
380+
381+
start = apr_time_now();
382+
383+
while (apr_time_now() < start + apr_time_from_sec(1))
384+
{
385+
SVN_ERR(svn_checksum_update(ctx, buf, blocksize));
386+
count++;
387+
}
388+
389+
SVN_ERR(svn_checksum_final(&checksum, ctx, pool));
390+
391+
{
392+
apr_size_t bytes_in_gb = 1024 * 1024 * 1024;
393+
apr_size_t bytes = count * blocksize;
394+
395+
/* Calling svn_checksum_serialize() is the simplest way to stringify
396+
* checksum kind yet, althrough it also includes extra information such as
397+
* the digest itself. */
398+
const char *checksum_str = svn_checksum_serialize(checksum, pool, pool);
399+
400+
fprintf(stderr,
401+
"%s: processed %ld blocks of %ld bytes (%.2f GB) in 1 second\n",
402+
checksum_str, count, blocksize, (double)bytes / bytes_in_gb);
403+
}
404+
405+
return SVN_NO_ERROR;
406+
}
407+
408+
static svn_error_t *
409+
test_checksum_performance(apr_pool_t *pool)
410+
{
411+
SVN_ERR(do_bench_test(/* 16 KB */ 16 * (1 << 10),
412+
svn_checksum_sha1, pool));
413+
SVN_ERR(do_bench_test(/* 1 MB */ 1 * (1 << 20),
414+
svn_checksum_sha1, pool));
415+
SVN_ERR(do_bench_test(/* 64 MB */ 64 * (1 << 20),
416+
svn_checksum_sha1, pool));
417+
SVN_ERR(do_bench_test(/* 16 B */ 16,
418+
svn_checksum_sha1, pool));
419+
420+
SVN_ERR(do_bench_test(/* 16 KB */ 16 * (1 << 10),
421+
svn_checksum_md5, pool));
422+
SVN_ERR(do_bench_test(/* 1 MB */ 1 * (1 << 20),
423+
svn_checksum_md5, pool));
424+
SVN_ERR(do_bench_test(/* 64 MB */ 64 * (1 << 20),
425+
svn_checksum_md5, pool));
426+
SVN_ERR(do_bench_test(/* 16 B */ 16,
427+
svn_checksum_md5, pool));
428+
429+
return SVN_NO_ERROR;
430+
}
431+
367432
/* An array of all test functions */
368433

369434
static int max_threads = 1;
@@ -389,6 +454,8 @@ static struct svn_test_descriptor_t test_funcs[] =
389454
"read from checksummed stream"),
390455
SVN_TEST_PASS2(test_checksummed_stream_reset,
391456
"reset checksummed stream"),
457+
SVN_TEST_PASS2(test_checksum_performance,
458+
"test checksum performance"),
392459
SVN_TEST_NULL
393460
};
394461

0 commit comments

Comments
 (0)