예제 #1
0
static void
do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src,
	     size_t len)
{
  size_t i, iters = INNER_LOOP_ITERS;
  timing_t start, stop, cur;

  TIMING_NOW (start);
  for (i = 0; i < iters; ++i)
    {
      CALL (impl, dst, src, len);
    }
  TIMING_NOW (stop);

  TIMING_DIFF (cur, start, stop);

  json_element_double (json_ctx, (double) cur / (double) iters);
}
예제 #2
0
static void
do_one_test (json_ctx_t *json_ctx, impl_t *impl,
	     const CHAR *s1, const CHAR *s2,
	     int exp_result)
{
  size_t i, iters = INNER_LOOP_ITERS;
  timing_t start, stop, cur;

  TIMING_NOW (start);
  for (i = 0; i < iters; ++i)
    {
      CALL (impl, s1, s2);
    }
  TIMING_NOW (stop);

  TIMING_DIFF (cur, start, stop);

  json_element_double (json_ctx, (double) cur / (double) iters);
}
예제 #3
0
static void
do_one_test (json_ctx_t *json_ctx, impl_t *impl, char *dst, char *src,
	     size_t len)
{
  size_t i = 0;
  timing_t start, stop, cur;

  char *dst_end = dst + MIN_PAGE_SIZE - len;
  char *src_end = src + MIN_PAGE_SIZE - len;

  TIMING_NOW (start);
  /* Copy the entire buffer backwards, LEN at a time.  */
  for (; src_end >= src && dst_end >= dst; src_end -= len, dst_end -= len, i++)
    CALL (impl, src_end, dst_end, len);
  TIMING_NOW (stop);

  TIMING_DIFF (cur, start, stop);

  /* Get time taken per function call.  */
  json_element_double (json_ctx, (double) cur / i);
}
예제 #4
0
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;
}