[PATCH v5] benchtest: malloc tcache hotpath benchtest.
Wilco Dijkstra
Wilco.Dijkstra@arm.com
Wed May 14 20:22:46 GMT 2025
Hi Cupertino,
We're getting there! Just one thing to ensure the benchmark loop runs
properly across all targets and compilers. It uses a division, however if
we change the 2nd loop to use 4 rather than 5 items, and force it to be
always inlined, it is optimized and then it all works perfectly.
Other than that, it looks good.
Cheers,
Wilco
+static size_t
+malloc_benchmark_loop (void **elems, size_t nr_items)
Should be __always_inline so the division can be optimized.
+{
+ size_t iters = nr_items;
+
+ while (!timeout)
+ {
+ elems[iters % nr_items] = TEST_FUNC (alloc_size);
+ iters++;
+ free (elems[iters % nr_items]);
+ }
+
+ return iters - nr_items;
+}
+
+static void
+do_benchmark (struct bench_result *res)
+{
+ timing_t start, stop;
+ void *elems[10];
+ memset (elems, 0, sizeof(void *) * 10);
I think sizeof (elems) is simpler and safer.
+
+ /* Ramp up cpu before measuring. */
+ alarm (BENCHMARK_DURATION);
+ bench_start ();
+ TIMING_NOW (start);
+ res[0].iters = malloc_benchmark_loop (elems, 1);
+ TIMING_NOW (stop);
+ TIMING_DIFF (res[0].elapsed, start, stop);
+
+ timeout = false;
+ alarm (BENCHMARK_DURATION);
+ bench_start ();
+ TIMING_NOW (start);
+ res[1].iters = malloc_benchmark_loop (elems, 5);
This should be 4 to avoid an expensive division.
More information about the Libc-alpha
mailing list