v13-0003-Attempt-to-make-benchmark-more-sensitive-to-late.patch.nocfbot
application/octet-stream
Filename: v13-0003-Attempt-to-make-benchmark-more-sensitive-to-late.patch.nocfbot
Type: application/octet-stream
Part: 2
From 65814a642b82a1f313eae2e3aada785af1f65be4 Mon Sep 17 00:00:00 2001
From: John Naylor <john.naylor@postgresql.org>
Date: Wed, 5 Mar 2025 07:52:52 +0700
Subject: [PATCH v13 3/3] Attempt to make benchmark more sensitive to latency
---
contrib/test_crc32c/test_crc32c.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/contrib/test_crc32c/test_crc32c.c b/contrib/test_crc32c/test_crc32c.c
index 28bc42de314..3e5ebad4e39 100644
--- a/contrib/test_crc32c/test_crc32c.c
+++ b/contrib/test_crc32c/test_crc32c.c
@@ -21,13 +21,13 @@ drive_crc32c(PG_FUNCTION_ARGS)
{
int64 count = PG_GETARG_INT32(0);
int64 num = PG_GETARG_INT32(1);
- char* data = malloc((size_t)num);
- pg_crc32c crc;
+ char* data = malloc((size_t)num + 256);
+ pg_crc32c crc = 0;
pg_prng_state state;
uint64 seed = 42;
pg_prng_seed(&state, seed);
/* set random data */
- for (uint64 i = 0; i < num; i++)
+ for (uint64 i = 0; i < num + 256; i++)
{
data[i] = pg_prng_uint32(&state) % 255;
}
@@ -36,11 +36,15 @@ drive_crc32c(PG_FUNCTION_ARGS)
while(count--)
{
- INIT_CRC32C(crc);
- COMP_CRC32C(crc, data, num);
- FIN_CRC32C(crc);
+ size_t delta = crc & 7;
+
+ /* make both pointer and length unpredictable */
+ COMP_CRC32C(crc, data + delta, num + delta);
+ /* simulate WAL header */
+ COMP_CRC32C(crc, data + delta, 20);
}
+ FIN_CRC32C(crc);
free((void *)data);
PG_RETURN_INT64((int64_t)crc);
--
2.48.1