Blame benchtests/bench-memset-walk.c

Packit Service 82fcde
/* Measure memset function throughput with large data sizes.
Packit Service 82fcde
   Copyright (C) 2017-2018 Free Software Foundation, Inc.
Packit Service 82fcde
   This file is part of the GNU C Library.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is free software; you can redistribute it and/or
Packit Service 82fcde
   modify it under the terms of the GNU Lesser General Public
Packit Service 82fcde
   License as published by the Free Software Foundation; either
Packit Service 82fcde
   version 2.1 of the License, or (at your option) any later version.
Packit Service 82fcde
Packit Service 82fcde
   The GNU C Library is distributed in the hope that it will be useful,
Packit Service 82fcde
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service 82fcde
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit Service 82fcde
   Lesser General Public License for more details.
Packit Service 82fcde
Packit Service 82fcde
   You should have received a copy of the GNU Lesser General Public
Packit Service 82fcde
   License along with the GNU C Library; if not, see
Packit Service 82fcde
   <http://www.gnu.org/licenses/>.  */
Packit Service 82fcde
Packit Service 82fcde
#define TEST_MAIN
Packit Service 82fcde
#ifndef WIDE
Packit Service 82fcde
# define TEST_NAME "memset"
Packit Service 82fcde
#else
Packit Service 82fcde
# define TEST_NAME "wmemset"
Packit Service 82fcde
#endif /* WIDE */
Packit Service 82fcde
#define START_SIZE 128
Packit Service 82fcde
#define MIN_PAGE_SIZE (getpagesize () + 32 * 1024 * 1024)
Packit Service 82fcde
#define TIMEOUT (20 * 60)
Packit Service 82fcde
#include "bench-string.h"
Packit Service 82fcde
Packit Service 82fcde
#ifndef WIDE
Packit Service 82fcde
# define MEMSET memset
Packit Service 82fcde
# define CHAR char
Packit Service 82fcde
# define SIMPLE_MEMSET simple_memset
Packit Service 82fcde
# define MEMCMP memcmp
Packit Service 82fcde
#else
Packit Service 82fcde
# include <wchar.h>
Packit Service 82fcde
# define MEMSET wmemset
Packit Service 82fcde
# define CHAR wchar_t
Packit Service 82fcde
# define SIMPLE_MEMSET simple_wmemset
Packit Service 82fcde
# define MEMCMP wmemcmp
Packit Service 82fcde
#endif /* WIDE */
Packit Service 82fcde
Packit Service 82fcde
#include <assert.h>
Packit Service 82fcde
#include "json-lib.h"
Packit Service 82fcde
Packit Service 82fcde
Packit Service 82fcde
typedef CHAR *(*proto_t) (CHAR *, int, size_t);
Packit Service 82fcde
Packit Service 82fcde
CHAR *
Packit Service 82fcde
inhibit_loop_to_libcall
Packit Service 82fcde
SIMPLE_MEMSET (CHAR *s, int c, size_t n)
Packit Service 82fcde
{
Packit Service 82fcde
  CHAR *r = s, *end = s + n;
Packit Service 82fcde
  while (r < end)
Packit Service 82fcde
    *r++ = c;
Packit Service 82fcde
  return s;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
IMPL (SIMPLE_MEMSET, 1)
Packit Service 82fcde
Packit Service 82fcde
static void
Packit Service 82fcde
do_one_test (json_ctx_t *json_ctx, impl_t *impl, CHAR *s, CHAR *s_end,
Packit Service 82fcde
	     int c __attribute ((unused)), size_t n)
Packit Service 82fcde
{
Packit Service 82fcde
  size_t i, iters = MIN_PAGE_SIZE / n;
Packit Service 82fcde
  timing_t start, stop, cur;
Packit Service 82fcde
Packit Service 82fcde
  TIMING_NOW (start);
Packit Service 82fcde
  for (i = 0; i < iters && s <= s_end; s_end -= n, i++)
Packit Service 82fcde
    CALL (impl, s, c, n);
Packit Service 82fcde
  TIMING_NOW (stop);
Packit Service 82fcde
Packit Service 82fcde
  TIMING_DIFF (cur, start, stop);
Packit Service 82fcde
Packit Service 82fcde
  /* Get time taken per function call.  */
Packit Service 82fcde
  json_element_double (json_ctx, (double) cur / i);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
static void
Packit Service 82fcde
do_test (json_ctx_t *json_ctx, int c, size_t len)
Packit Service 82fcde
{
Packit Service 82fcde
  json_element_object_begin (json_ctx);
Packit Service 82fcde
  json_attr_uint (json_ctx, "length", len);
Packit Service 82fcde
  json_attr_uint (json_ctx, "char", c);
Packit Service 82fcde
  json_array_begin (json_ctx, "timings");
Packit Service 82fcde
Packit Service 82fcde
  FOR_EACH_IMPL (impl, 0)
Packit Service 82fcde
    {
Packit Service 82fcde
      do_one_test (json_ctx, impl, (CHAR *) buf1,
Packit Service 82fcde
		   (CHAR *) buf1 + MIN_PAGE_SIZE - len, c, len);
Packit Service 82fcde
      realloc_bufs ();
Packit Service 82fcde
    }
Packit Service 82fcde
Packit Service 82fcde
  json_array_end (json_ctx);
Packit Service 82fcde
  json_element_object_end (json_ctx);
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
int
Packit Service 82fcde
test_main (void)
Packit Service 82fcde
{
Packit Service 82fcde
  json_ctx_t json_ctx;
Packit Service 82fcde
  size_t i;
Packit Service 82fcde
Packit Service 82fcde
  test_init ();
Packit Service 82fcde
Packit Service 82fcde
  json_init (&json_ctx, 0, stdout);
Packit Service 82fcde
Packit Service 82fcde
  json_document_begin (&json_ctx);
Packit Service 82fcde
  json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
Packit Service 82fcde
Packit Service 82fcde
  json_attr_object_begin (&json_ctx, "functions");
Packit Service 82fcde
  json_attr_object_begin (&json_ctx, TEST_NAME);
Packit Service 82fcde
  json_attr_string (&json_ctx, "bench-variant", "walk");
Packit Service 82fcde
Packit Service 82fcde
  json_array_begin (&json_ctx, "ifuncs");
Packit Service 82fcde
  FOR_EACH_IMPL (impl, 0)
Packit Service 82fcde
    json_element_string (&json_ctx, impl->name);
Packit Service 82fcde
  json_array_end (&json_ctx);
Packit Service 82fcde
Packit Service 82fcde
  json_array_begin (&json_ctx, "results");
Packit Service 82fcde
  for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
Packit Service 82fcde
      /* Test length alignments from 0-16 bytes.  */
Packit Service 82fcde
      for (int j = 0; j < i && j < 16; j++)
Packit Service 82fcde
	do_test (&json_ctx, 65, i + j);
Packit Service 82fcde
Packit Service 82fcde
  for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
Packit Service 82fcde
      for (int j = 0; j < i && j < 16; j++)
Packit Service 82fcde
	do_test (&json_ctx, 0, i + j);
Packit Service 82fcde
Packit Service 82fcde
  json_array_end (&json_ctx);
Packit Service 82fcde
  json_attr_object_end (&json_ctx);
Packit Service 82fcde
  json_attr_object_end (&json_ctx);
Packit Service 82fcde
  json_document_end (&json_ctx);
Packit Service 82fcde
Packit Service 82fcde
  return ret;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#include <support/test-driver.c>