v12-0002-Attempt-to-make-benchmark-more-sensitive-to-late.patch

text/x-patch

Filename: v12-0002-Attempt-to-make-benchmark-more-sensitive-to-late.patch
Type: text/x-patch
Part: 4
Message: Re: Improve CRC32C performance on SSE4.2

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v12-0002
Subject: Attempt to make benchmark more sensitive to latency
File+
contrib/test_crc32c/test_crc32c.c 10 6
From 7a9b94677da30db0f8c296fe71037f65b157bc1c 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 v12 2/6] 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