Blame benchtests/bench-strtod.c

Packit 6c4009
/* Measure strtod implementation.
Packit 6c4009
   Copyright (C) 2013-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#define TEST_MAIN
Packit 6c4009
#define TEST_NAME "strtod"
Packit 6c4009
Packit 6c4009
#include <stdio.h>
Packit 6c4009
#include <stdlib.h>
Packit 6c4009
#include "bench-timing.h"
Packit 6c4009
Packit 6c4009
#undef INNER_LOOP_ITERS
Packit 6c4009
#define INNER_LOOP_ITERS 65536
Packit 6c4009
Packit 6c4009
static const char *inputs[] =
Packit 6c4009
{
Packit 6c4009
  "1e308",
Packit 6c4009
  "100000000e300",
Packit 6c4009
  "0x1p1023",
Packit 6c4009
  "0x1000p1011",
Packit 6c4009
  "0x1p1020",
Packit 6c4009
  "0x0.00001p1040" "1e-307",
Packit 6c4009
  "0.000001e-301",
Packit 6c4009
  "0.0000001e-300",
Packit 6c4009
  "0.00000001e-299",
Packit 6c4009
  "1000000e-313",
Packit 6c4009
  "10000000e-314",
Packit 6c4009
  "100000000e-315",
Packit 6c4009
  "0x1p-1021",
Packit 6c4009
  "0x1000p-1033",
Packit 6c4009
  "0x10000p-1037",
Packit 6c4009
  "0x0.001p-1009",
Packit 6c4009
  "0x0.0001p-1005",
Packit 6c4009
  "12.345",
Packit 6c4009
  "12.345e19",
Packit 6c4009
  "-.1e+9",
Packit 6c4009
  ".125",
Packit 6c4009
  "1e20",
Packit 6c4009
  "0e-19",
Packit 6c4009
  "4\00012",
Packit 6c4009
  "5.9e-76",
Packit 6c4009
  "0x1.4p+3",
Packit 6c4009
  "0xAp0",
Packit 6c4009
  "0x0Ap0",
Packit 6c4009
  "0x0A",
Packit 6c4009
  "0xA0",
Packit 6c4009
  "0x0.A0p8",
Packit 6c4009
  "0x0.50p9",
Packit 6c4009
  "0x0.28p10",
Packit 6c4009
  "0x0.14p11",
Packit 6c4009
  "0x0.0A0p12",
Packit 6c4009
  "0x0.050p13",
Packit 6c4009
  "0x0.028p14",
Packit 6c4009
  "0x0.014p15",
Packit 6c4009
  "0x00.00A0p16",
Packit 6c4009
  "0x00.0050p17",
Packit 6c4009
  "0x00.0028p18",
Packit 6c4009
  "0x00.0014p19",
Packit 6c4009
  "0x1p-1023",
Packit 6c4009
  "0x0.8p-1022",
Packit 6c4009
  "Inf",
Packit 6c4009
  "-Inf",
Packit 6c4009
  "+InFiNiTy",
Packit 6c4009
  "0x80000Ap-23",
Packit 6c4009
  "1e-324",
Packit 6c4009
  "0x100000000000008p0",
Packit 6c4009
  "0x100000000000008.p0",
Packit 6c4009
  "0x100000000000008.00p0",
Packit 6c4009
  "0x10000000000000800p0",
Packit 6c4009
  "0x10000000000000801p0",
Packit 6c4009
  NULL
Packit 6c4009
};
Packit 6c4009
Packit 6c4009
int
Packit 6c4009
do_bench (void)
Packit 6c4009
{
Packit 6c4009
  const size_t iters = INNER_LOOP_ITERS;
Packit 6c4009
  timing_t res __attribute__ ((unused));
Packit 6c4009
Packit 6c4009
  TIMING_INIT (res);
Packit 6c4009
Packit 6c4009
  for (size_t i = 0; inputs[i] != NULL; ++i)
Packit 6c4009
    {
Packit 6c4009
      char *ep;
Packit 6c4009
      timing_t start, stop, cur;
Packit 6c4009
Packit 6c4009
      printf ("Input %-24s:", inputs[i]);
Packit 6c4009
      TIMING_NOW (start);
Packit 6c4009
      for (size_t j = 0; j < iters; ++j)
Packit 6c4009
	strtod (inputs[i], &ep);
Packit 6c4009
      TIMING_NOW (stop);
Packit 6c4009
Packit 6c4009
      TIMING_DIFF (cur, start, stop);
Packit 6c4009
      TIMING_PRINT_MEAN ((double) cur, (double) iters);
Packit 6c4009
      putchar ('\n');
Packit 6c4009
    }
Packit 6c4009
Packit 6c4009
  return 0;
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#define TEST_FUNCTION do_bench ()
Packit 6c4009
Packit 6c4009
/* On slower platforms this test needs more than the default 2 seconds.  */
Packit 6c4009
#define TIMEOUT 10
Packit 6c4009
Packit 6c4009
#include "../test-skeleton.c"