コード例 #1
0
ファイル: bench-strcmp.c プロジェクト: ddstreet/glibc
int
test_main (void)
{
  json_ctx_t json_ctx;
  size_t i;

  test_init ();

  json_init (&json_ctx, 0, stdout);

  json_document_begin (&json_ctx);
  json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);

  json_attr_object_begin (&json_ctx, "functions");
  json_attr_object_begin (&json_ctx, TEST_NAME);
  json_attr_string (&json_ctx, "bench-variant", "default");

  json_array_begin (&json_ctx, "ifuncs");
  FOR_EACH_IMPL (impl, 0)
    json_element_string (&json_ctx, impl->name);
  json_array_end (&json_ctx);

  json_array_begin (&json_ctx, "results");

  for (i = 1; i < 32; ++i)
    {
      do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, 0);
      do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, 1);
      do_test (&json_ctx, CHARBYTES * i, CHARBYTES * i, i, MIDCHAR, -1);
    }

  for (i = 1; i < 10 + CHARBYTESLOG; ++i)
    {
      do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, 0);
      do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, 0);
      do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, 1);
      do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, 1);
      do_test (&json_ctx, 0, 0, 2 << i, MIDCHAR, -1);
      do_test (&json_ctx, 0, 0, 2 << i, LARGECHAR, -1);
      do_test (&json_ctx, 0, CHARBYTES * i, 2 << i, MIDCHAR, 1);
      do_test (&json_ctx, CHARBYTES * i, CHARBYTES * (i + 1), 2 << i, LARGECHAR, 1);
    }

  for (i = 1; i < 8; ++i)
    {
      do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, MIDCHAR, 0);
      do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, 0);
      do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, MIDCHAR, 1);
      do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, 1);
      do_test (&json_ctx, CHARBYTES * i, 2 * CHARBYTES * i, 8 << i, MIDCHAR, -1);
      do_test (&json_ctx, 2 * CHARBYTES * i, CHARBYTES * i, 8 << i, LARGECHAR, -1);
    }

  json_array_end (&json_ctx);
  json_attr_object_end (&json_ctx);
  json_attr_object_end (&json_ctx);
  json_document_end (&json_ctx);

  return ret;
}
コード例 #2
0
ファイル: bench-memmove-walk.c プロジェクト: bminor/glibc
int
test_main (void)
{
  json_ctx_t json_ctx;

  test_init ();

  json_init (&json_ctx, 0, stdout);

  json_document_begin (&json_ctx);
  json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);

  json_attr_object_begin (&json_ctx, "functions");
  json_attr_object_begin (&json_ctx, "memmove");
  json_attr_string (&json_ctx, "bench-variant", "walk");

  json_array_begin (&json_ctx, "ifuncs");
  FOR_EACH_IMPL (impl, 0)
    json_element_string (&json_ctx, impl->name);
  json_array_end (&json_ctx);

  json_array_begin (&json_ctx, "results");
  /* Non-overlapping buffers.  */
  for (size_t i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
    {
      do_test (&json_ctx, i, false);
      do_test (&json_ctx, i + 1, false);
    }

  /* Overlapping buffers.  */
  for (size_t i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
    {
      do_test (&json_ctx, i, true);
      do_test (&json_ctx, i + 1, true);
    }

  json_array_end (&json_ctx);
  json_attr_object_end (&json_ctx);
  json_attr_object_end (&json_ctx);
  json_document_end (&json_ctx);

  return ret;
}
コード例 #3
0
ファイル: bench-math-inlines.c プロジェクト: Distrotech/glibc
int
test_main (void)
{
  json_ctx_t json_ctx;
  size_t i;

  bench_start ();

  json_init (&json_ctx, 2, stdout);
  json_attr_object_begin (&json_ctx, TEST_NAME);

  /* Create 2 test arrays, one with 10% zeroes, 10% negative values,
     79% positive values and 1% infinity/NaN.  The other contains
     50% inf, 50% NaN.  This relies on rand behaving correctly.  */

  for (i = 0; i < SIZE; i++)
    {
      int x = rand () & 255;
      arr1[i] = (x < 25) ? 0.0 : ((x < 50) ? -1 : 100);
      if (x == 255) arr1[i] = __builtin_inf ();
      if (x == 254) arr1[i] = __builtin_nan ("0");
      arr2[i] = (x < 128) ? __builtin_inf () : __builtin_nan ("0");
    }

  for (i = 0; i < sizeof (test_list) / sizeof (test_list[0]); i++)
    {
      json_attr_object_begin (&json_ctx, test_list[i].name);
      do_one_test (&json_ctx, test_list[i].fn, arr2, SIZE, "inf/nan");
      json_attr_object_end (&json_ctx);
    }

  for (i = 0; i < sizeof (test_list) / sizeof (test_list[0]); i++)
    {
      json_attr_object_begin (&json_ctx, test_list[i].name);
      do_one_test (&json_ctx, test_list[i].fn, arr1, SIZE, "normal");
      json_attr_object_end (&json_ctx);
    }

  json_attr_object_end (&json_ctx);
  return 0;
}
コード例 #4
0
ファイル: bench-memcpy-walk.c プロジェクト: riscv/riscv-glibc
int
test_main (void)
{
  json_ctx_t json_ctx;
  size_t i;

  test_init ();

  json_init (&json_ctx, 0, stdout);

  json_document_begin (&json_ctx);
  json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);

  json_attr_object_begin (&json_ctx, "functions");
  json_attr_object_begin (&json_ctx, "memcpy");
  json_attr_string (&json_ctx, "bench-variant", "walk");

  json_array_begin (&json_ctx, "ifuncs");
  FOR_EACH_IMPL (impl, 0)
    json_element_string (&json_ctx, impl->name);
  json_array_end (&json_ctx);

  json_array_begin (&json_ctx, "results");
  for (i = START_SIZE; i <= MIN_PAGE_SIZE; i <<= 1)
    {
      /* Test length alignments from 0-16 bytes.  */
      for (int j = 0; j < 8; j++)
	{
	  do_test (&json_ctx, i + j);
	  do_test (&json_ctx, i + 16 - j);
	}
    }

  json_array_end (&json_ctx);
  json_attr_object_end (&json_ctx);
  json_attr_object_end (&json_ctx);
  json_document_end (&json_ctx);

  return ret;
}
コード例 #5
0
ファイル: bench-math-inlines.c プロジェクト: Distrotech/glibc
static void
do_one_test (json_ctx_t *json_ctx, proto_t test_fn, volatile double *arr,
	     size_t len, const char *testname)
{
  size_t iters = 500;
  timing_t start, stop, cur;

  json_attr_object_begin (json_ctx, testname);

  TIMING_NOW (start);
  test_fn (arr, len, iters);
  TIMING_NOW (stop);
  TIMING_DIFF (cur, start, stop);

  json_attr_double (json_ctx, "duration", cur);
  json_attr_double (json_ctx, "iterations", iters);
  json_attr_double (json_ctx, "mean", cur / iters);
  json_attr_object_end (json_ctx);
}
コード例 #6
0
ファイル: bench-skeleton.c プロジェクト: Distrotech/glibc
int
main (int argc, char **argv)
{
  unsigned long i, k;
  struct timespec runtime;
  timing_t start, end;
  bool detailed = false;
  json_ctx_t json_ctx;

  if (argc == 2 && !strcmp (argv[1], "-d"))
    detailed = true;

  bench_start ();

  memset (&runtime, 0, sizeof (runtime));

  unsigned long iters, res;

#ifdef BENCH_INIT
  BENCH_INIT ();
#endif
  TIMING_INIT (res);

  iters = 1000 * res;

  json_init (&json_ctx, 2, stdout);

  /* Begin function.  */
  json_attr_object_begin (&json_ctx, FUNCNAME);

  for (int v = 0; v < NUM_VARIANTS; v++)
    {
      /* Run for approximately DURATION seconds.  */
      clock_gettime (CLOCK_MONOTONIC_RAW, &runtime);
      runtime.tv_sec += DURATION;

      double d_total_i = 0;
      timing_t total = 0, max = 0, min = 0x7fffffffffffffff;
      int64_t c = 0;
      while (1)
	{
	  for (i = 0; i < NUM_SAMPLES (v); i++)
	    {
	      uint64_t cur;
	      TIMING_NOW (start);
	      for (k = 0; k < iters; k++)
		BENCH_FUNC (v, i);
	      TIMING_NOW (end);

	      TIMING_DIFF (cur, start, end);

	      if (cur > max)
		max = cur;

	      if (cur < min)
		min = cur;

	      TIMING_ACCUM (total, cur);
	      /* Accumulate timings for the value.  In the end we will divide
	         by the total iterations.  */
	      RESULT_ACCUM (cur, v, i, c * iters, (c + 1) * iters);

	      d_total_i += iters;
	    }
	  c++;
	  struct timespec curtime;

	  memset (&curtime, 0, sizeof (curtime));
	  clock_gettime (CLOCK_MONOTONIC_RAW, &curtime);
	  if (TIMESPEC_AFTER (curtime, runtime))
	    goto done;
	}

      double d_total_s;
      double d_iters;

    done:
      d_total_s = total;
      d_iters = iters;

      /* Begin variant.  */
      json_attr_object_begin (&json_ctx, VARIANT (v));

      json_attr_double (&json_ctx, "duration", d_total_s);
      json_attr_double (&json_ctx, "iterations", d_total_i);
      json_attr_double (&json_ctx, "max", max / d_iters);
      json_attr_double (&json_ctx, "min", min / d_iters);
      json_attr_double (&json_ctx, "mean", d_total_s / d_total_i);

      if (detailed)
	{
	  json_array_begin (&json_ctx, "timings");

	  for (int i = 0; i < NUM_SAMPLES (v); i++)
	    json_element_double (&json_ctx, RESULT (v, i));

	  json_array_end (&json_ctx);
	}

      /* End variant.  */
      json_attr_object_end (&json_ctx);
    }

  /* End function.  */
  json_attr_object_end (&json_ctx);

  return 0;
}
コード例 #7
0
ファイル: bench-malloc-thread.c プロジェクト: Xilinx/glibc
int
main (int argc, char **argv)
{
  timing_t cur;
  size_t iters = 0, num_threads = 1;
  unsigned long res;
  json_ctx_t json_ctx;
  double d_total_s, d_total_i;
  struct sigaction act;

  if (argc == 1)
    num_threads = 1;
  else if (argc == 2)
    {
      long ret;

      errno = 0;
      ret = strtol(argv[1], NULL, 10);

      if (errno || ret == 0)
	usage(argv[0]);

      num_threads = ret;
    }
  else
    usage(argv[0]);

  init_random_values ();

  json_init (&json_ctx, 0, stdout);

  json_document_begin (&json_ctx);

  json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);

  json_attr_object_begin (&json_ctx, "functions");

  json_attr_object_begin (&json_ctx, "malloc");

  json_attr_object_begin (&json_ctx, "");

  TIMING_INIT (res);

  (void) res;

  memset (&act, 0, sizeof (act));
  act.sa_handler = &alarm_handler;

  sigaction (SIGALRM, &act, NULL);

  alarm (BENCHMARK_DURATION);

  cur = do_benchmark (num_threads, &iters);

  struct rusage usage;
  getrusage(RUSAGE_SELF, &usage);

  d_total_s = cur;
  d_total_i = iters;

  json_attr_double (&json_ctx, "duration", d_total_s);
  json_attr_double (&json_ctx, "iterations", d_total_i);
  json_attr_double (&json_ctx, "time_per_iteration", d_total_s / d_total_i);
  json_attr_double (&json_ctx, "max_rss", usage.ru_maxrss);

  json_attr_double (&json_ctx, "threads", num_threads);
  json_attr_double (&json_ctx, "min_size", MIN_ALLOCATION_SIZE);
  json_attr_double (&json_ctx, "max_size", MAX_ALLOCATION_SIZE);
  json_attr_double (&json_ctx, "random_seed", RAND_SEED);

  json_attr_object_end (&json_ctx);

  json_attr_object_end (&json_ctx);

  json_attr_object_end (&json_ctx);

  json_document_end (&json_ctx);

  return 0;
}
コード例 #8
0
ファイル: bench-memmove.c プロジェクト: bminor/glibc
static int
test_main (void)
{
  json_ctx_t json_ctx;
  size_t i;

  test_init ();

  json_init (&json_ctx, 0, stdout);

  json_document_begin (&json_ctx);
  json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);

  json_attr_object_begin (&json_ctx, "functions");
  json_attr_object_begin (&json_ctx, "memmove");
  json_attr_string (&json_ctx, "bench-variant", "default");

  json_array_begin (&json_ctx, "ifuncs");

  FOR_EACH_IMPL (impl, 0)
    json_element_string (&json_ctx, impl->name);
  json_array_end (&json_ctx);

  json_array_begin (&json_ctx, "results");
  for (i = 0; i < 14; ++i)
    {
      do_test (&json_ctx, 0, 32, 1 << i);
      do_test (&json_ctx, 32, 0, 1 << i);
      do_test (&json_ctx, 0, i, 1 << i);
      do_test (&json_ctx, i, 0, 1 << i);
    }

  for (i = 0; i < 32; ++i)
    {
      do_test (&json_ctx, 0, 32, i);
      do_test (&json_ctx, 32, 0, i);
      do_test (&json_ctx, 0, i, i);
      do_test (&json_ctx, i, 0, i);
    }

  for (i = 3; i < 32; ++i)
    {
      if ((i & (i - 1)) == 0)
	continue;
      do_test (&json_ctx, 0, 32, 16 * i);
      do_test (&json_ctx, 32, 0, 16 * i);
      do_test (&json_ctx, 0, i, 16 * i);
      do_test (&json_ctx, i, 0, 16 * i);
    }

  for (i = 32; i < 64; ++i)
    {
      do_test (&json_ctx, 0, 0, 32 * i);
      do_test (&json_ctx, i, 0, 32 * i);
      do_test (&json_ctx, 0, i, 32 * i);
      do_test (&json_ctx, i, i, 32 * i);
    }

  json_array_end (&json_ctx);
  json_attr_object_end (&json_ctx);
  json_attr_object_end (&json_ctx);
  json_document_end (&json_ctx);

  return ret;
}