benchtests: Improve bench-memcpy-random

Improve the random memcpy benchmark. Double the number of tests and increase
the size of the memory region to test between 32KB and 1024KB. This improves
accuracy on modern cores. Clean up formatting of the frequency array.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
This commit is contained in:
Wilco Dijkstra 2021-10-29 15:41:18 +01:00
parent 7ca9377bab
commit f392915d1e

View File

@ -16,15 +16,17 @@
License along with the GNU C Library; if not, see
<https://www.gnu.org/licenses/>. */
#define MIN_PAGE_SIZE (512*1024+getpagesize())
#define MIN_SIZE 32768
#define MAX_SIZE (1024*1024)
#define NUM_TESTS 16384
#define MIN_PAGE_SIZE (MAX_SIZE + getpagesize())
#define TEST_MAIN
#define TEST_NAME "memcpy"
#include "bench-string.h"
#include <assert.h>
#include "json-lib.h"
#define MAX_COPIES 8192
IMPL (memcpy, 1)
typedef struct { uint16_t size; uint16_t freq; } freq_data_t;
@ -37,12 +39,12 @@ static uint8_t size_arr[SIZE_NUM];
/* Frequency data for memcpy of less than 4096 bytes based on SPEC2017. */
static freq_data_t size_freq[] =
{
{ 32, 22320}, { 16, 9554}, { 8, 8915}, {152, 5327}, { 4, 2159}, {292, 2035},
{ 12, 1608}, { 24, 1343}, {1152, 895}, {144, 813}, {884, 733}, {284, 721},
{32,22320}, { 16,9554}, { 8,8915}, {152,5327}, { 4,2159}, {292,2035},
{ 12,1608}, { 24,1343}, {1152,895}, {144, 813}, {884, 733}, {284, 721},
{120, 661}, { 2, 649}, {882, 550}, { 5, 475}, { 7, 461}, {108, 460},
{ 10, 361}, { 9, 361}, { 6, 334}, { 3, 326}, {464, 308}, {2048, 303},
{ 10, 361}, { 9, 361}, { 6, 334}, { 3, 326}, {464, 308}, {2048,303},
{ 1, 298}, { 64, 250}, { 11, 197}, {296, 194}, { 68, 187}, { 15, 185},
{192, 184}, {1764, 183}, { 13, 173}, {560, 126}, {160, 115}, {288, 96},
{192, 184}, {1764,183}, { 13, 173}, {560, 126}, {160, 115}, {288, 96},
{104, 96}, {1144, 83}, { 18, 80}, { 23, 78}, { 40, 77}, { 19, 68},
{ 48, 63}, { 17, 57}, { 72, 54}, {1280, 51}, { 20, 49}, { 28, 47},
{ 22, 46}, {640, 45}, { 25, 41}, { 14, 40}, { 56, 37}, { 27, 35},
@ -94,7 +96,7 @@ typedef struct
uint64_t len : 16;
} copy_t;
static copy_t copy[MAX_COPIES];
static copy_t test_arr[NUM_TESTS];
typedef char *(*proto_t) (char *, const char *, size_t);
@ -150,13 +152,13 @@ do_test (json_ctx_t *json_ctx, size_t max_size)
/* Create a random set of copies with the given size and alignment
distributions. */
for (i = 0; i < MAX_COPIES; i++)
for (i = 0; i < NUM_TESTS; i++)
{
copy[i].dst = (rand () & (max_size - 1));
copy[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
copy[i].src = (rand () & (max_size - 1));
copy[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
copy[i].len = size_arr[rand () & SIZE_MASK];
test_arr[i].dst = (rand () & (max_size - 1));
test_arr[i].dst &= ~dst_align_arr[rand () & ALIGN_MASK];
test_arr[i].src = (rand () & (max_size - 1));
test_arr[i].src &= ~src_align_arr[rand () & ALIGN_MASK];
test_arr[i].len = size_arr[rand () & SIZE_MASK];
}
json_element_object_begin (json_ctx);
@ -164,7 +166,7 @@ do_test (json_ctx_t *json_ctx, size_t max_size)
json_array_begin (json_ctx, "timings");
FOR_EACH_IMPL (impl, 0)
do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, copy, i);
do_one_test (json_ctx, impl, (char *) buf2, (char *) buf1, test_arr, i);
json_array_end (json_ctx);
json_element_object_end (json_ctx);
@ -193,8 +195,8 @@ test_main (void)
json_array_end (&json_ctx);
json_array_begin (&json_ctx, "results");
for (int i = 4; i <= 512; i = i * 2)
do_test (&json_ctx, i * 1024);
for (int i = MIN_SIZE; i <= MAX_SIZE; i = i * 2)
do_test (&json_ctx, i);
json_array_end (&json_ctx);
json_attr_object_end (&json_ctx);