(root)/
glibc-2.38/
benchtests/
bench-memmove-large.c
       1  /* Measure memmove functions with large data sizes.
       2     Copyright (C) 2016-2023 Free Software Foundation, Inc.
       3     This file is part of the GNU C Library.
       4  
       5     The GNU C Library is free software; you can redistribute it and/or
       6     modify it under the terms of the GNU Lesser General Public
       7     License as published by the Free Software Foundation; either
       8     version 2.1 of the License, or (at your option) any later version.
       9  
      10     The GNU C Library is distributed in the hope that it will be useful,
      11     but WITHOUT ANY WARRANTY; without even the implied warranty of
      12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      13     Lesser General Public License for more details.
      14  
      15     You should have received a copy of the GNU Lesser General Public
      16     License along with the GNU C Library; if not, see
      17     <https://www.gnu.org/licenses/>.  */
      18  
      19  #define BASE_PAGE_SIZE (1024 * 1024)
      20  #define START_SIZE (4 * 1024)
      21  #define MIN_PAGE_SIZE (getpagesize () + 16 * 1024 * 1024)
      22  #define TEST_MAIN
      23  #define TEST_NAME "memmove"
      24  #define TIMEOUT (20 * 60)
      25  #include "bench-string.h"
      26  #include "json-lib.h"
      27  
      28  IMPL (memmove, 1)
      29  
      30  typedef char *(*proto_t) (char *, const char *, size_t);
      31  
      32  static void
      33  do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src,
      34  	     size_t len)
      35  {
      36    size_t i, iters = 16;
      37    timing_t start, stop, cur;
      38  
      39    TIMING_NOW (start);
      40    for (i = 0; i < iters; ++i)
      41      {
      42        CALL (impl, dst, src, len);
      43      }
      44    TIMING_NOW (stop);
      45  
      46    TIMING_DIFF (cur, start, stop);
      47  
      48    json_element_double (json_ctx, (double) cur / (double) iters);
      49  }
      50  
      51  static void
      52  do_test (json_ctx_t *json_ctx, size_t align1, size_t align2, size_t len)
      53  {
      54    size_t i, j;
      55    char *s1, *s2;
      56  
      57    align1 &= 127;
      58    if (align1 + len >= page_size)
      59      return;
      60  
      61    align2 &= 127;
      62    if (align2 + len >= page_size)
      63      return;
      64  
      65    s1 = (char *) (buf2 + align1);
      66    s2 = (char *) (buf2 + align2);
      67  
      68    for (i = 0, j = 1; i < len; i++, j += 23)
      69      s1[i] = j;
      70  
      71    json_element_object_begin (json_ctx);
      72    json_attr_uint (json_ctx, "length", (double) len);
      73    json_attr_uint (json_ctx, "align1", (double) align1);
      74    json_attr_uint (json_ctx, "align2", (double) align2);
      75    json_array_begin (json_ctx, "timings");
      76  
      77    FOR_EACH_IMPL (impl, 0)
      78      do_one_test (json_ctx, impl, s2, s1, len);
      79  
      80    json_array_end (json_ctx);
      81    json_element_object_end (json_ctx);
      82  }
      83  
      84  int
      85  test_main (void)
      86  {
      87    json_ctx_t json_ctx;
      88    size_t i;
      89  
      90    test_init ();
      91  
      92    json_init (&json_ctx, 0, stdout);
      93  
      94    json_document_begin (&json_ctx);
      95    json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);
      96  
      97    json_attr_object_begin (&json_ctx, "functions");
      98    json_attr_object_begin (&json_ctx, "memmove");
      99    json_attr_string (&json_ctx, "bench-variant", "large");
     100  
     101    json_array_begin (&json_ctx, "ifuncs");
     102  
     103    FOR_EACH_IMPL (impl, 0)
     104      json_element_string (&json_ctx, impl->name);
     105    json_array_end (&json_ctx);
     106  
     107    json_array_begin (&json_ctx, "results");
     108    for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
     109      {
     110        do_test (&json_ctx, 0, 64, i + 7);
     111        do_test (&json_ctx, 0, 3, i + 15);
     112        do_test (&json_ctx, 3, 0, i + 31);
     113        do_test (&json_ctx, 3, 7, i + 63);
     114        do_test (&json_ctx, 9, 5, i + 127);
     115      }
     116  
     117    json_array_end (&json_ctx);
     118    json_attr_object_end (&json_ctx);
     119    json_attr_object_end (&json_ctx);
     120    json_document_end (&json_ctx);
     121  
     122    return ret;
     123  }
     124  
     125  #include <support/test-driver.c>