Author: rinrab
Date: Sun Dec 28 16:25:53 2025
New Revision: 1930929
Log:
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.
Modified:
subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c
Modified: subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c
==============================================================================
--- subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c Sun Dec
28 15:58:07 2025 (r1930928)
+++ subversion/trunk/subversion/tests/libsvn_subr/checksum-test.c Sun Dec
28 16:25:53 2025 (r1930929)
@@ -364,6 +364,71 @@ test_checksummed_stream_reset(apr_pool_t
return SVN_NO_ERROR;
}
+static svn_error_t *
+do_bench_test(apr_size_t blocksize, svn_checksum_kind_t kind, apr_pool_t *pool)
+{
+ svn_checksum_ctx_t *ctx = svn_checksum_ctx_create(kind, pool);
+ svn_checksum_t *checksum;
+ char *buf = apr_palloc(pool, blocksize);
+ apr_time_t start;
+ apr_size_t count = 0;
+ apr_uint32_t seed = 67;
+ apr_size_t i;
+
+ for (i = 0; i < blocksize; i++)
+ buf[i] = (char)svn_test_rand(&seed);
+
+ start = apr_time_now();
+
+ while (apr_time_now() < start + apr_time_from_sec(1))
+ {
+ SVN_ERR(svn_checksum_update(ctx, buf, blocksize));
+ count++;
+ }
+
+ SVN_ERR(svn_checksum_final(&checksum, ctx, pool));
+
+ {
+ apr_size_t bytes_in_gb = 1024 * 1024 * 1024;
+ apr_size_t bytes = count * blocksize;
+
+ /* Calling svn_checksum_serialize() is the simplest way to stringify
+ * checksum kind yet, althrough it also includes extra information such as
+ * the digest itself. */
+ const char *checksum_str = svn_checksum_serialize(checksum, pool, pool);
+
+ fprintf(stderr,
+ "%s: processed %ld blocks of %ld bytes (%.2f GB) in 1 second\n",
+ checksum_str, count, blocksize, (double)bytes / bytes_in_gb);
+ }
+
+ return SVN_NO_ERROR;
+}
+
+static svn_error_t *
+test_checksum_performance(apr_pool_t *pool)
+{
+ SVN_ERR(do_bench_test(/* 16 KB */ 16 * (1 << 10),
+ svn_checksum_sha1, pool));
+ SVN_ERR(do_bench_test(/* 1 MB */ 1 * (1 << 20),
+ svn_checksum_sha1, pool));
+ SVN_ERR(do_bench_test(/* 64 MB */ 64 * (1 << 20),
+ svn_checksum_sha1, pool));
+ SVN_ERR(do_bench_test(/* 16 B */ 16,
+ svn_checksum_sha1, pool));
+
+ SVN_ERR(do_bench_test(/* 16 KB */ 16 * (1 << 10),
+ svn_checksum_md5, pool));
+ SVN_ERR(do_bench_test(/* 1 MB */ 1 * (1 << 20),
+ svn_checksum_md5, pool));
+ SVN_ERR(do_bench_test(/* 64 MB */ 64 * (1 << 20),
+ svn_checksum_md5, pool));
+ SVN_ERR(do_bench_test(/* 16 B */ 16,
+ svn_checksum_md5, pool));
+
+ return SVN_NO_ERROR;
+}
+
/* An array of all test functions */
static int max_threads = 1;
@@ -389,6 +454,8 @@ static struct svn_test_descriptor_t test
"read from checksummed stream"),
SVN_TEST_PASS2(test_checksummed_stream_reset,
"reset checksummed stream"),
+ SVN_TEST_PASS2(test_checksum_performance,
+ "test checksum performance"),
SVN_TEST_NULL
};