Blame benchtests/bench-strcspn.c

Packit Service 82fcde
/* Measure strcspn functions.
Packit Service 82fcde
   Copyright (C) 2013-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 STRPBRK_RESULT(s, pos) (pos)
Packit Service 82fcde
#define RES_TYPE size_t
Packit Service 82fcde
#define TEST_MAIN
Packit Service 82fcde
#ifndef WIDE
Packit Service 82fcde
# define TEST_NAME "strcspn"
Packit Service 82fcde
#else
Packit Service 82fcde
# define TEST_NAME "wcscspn"
Packit Service 82fcde
#endif /* WIDE */
Packit Service 82fcde
#include "bench-string.h"
Packit Service 82fcde
Packit Service 82fcde
#ifndef WIDE
Packit Service 82fcde
# define STRCSPN strcspn
Packit Service 82fcde
# define CHAR char
Packit Service 82fcde
# define SIMPLE_STRCSPN simple_strcspn
Packit Service 82fcde
# define STUPID_STRCSPN stupid_strcspn
Packit Service 82fcde
# define STRLEN strlen
Packit Service 82fcde
#else
Packit Service 82fcde
# include <wchar.h>
Packit Service 82fcde
# define STRCSPN wcscspn
Packit Service 82fcde
# define CHAR wchar_t
Packit Service 82fcde
# define SIMPLE_STRCSPN simple_wcscspn
Packit Service 82fcde
# define STUPID_STRCSPN stupid_wcscspn
Packit Service 82fcde
# define STRLEN wcslen
Packit Service 82fcde
#endif /* WIDE */
Packit Service 82fcde
Packit Service 82fcde
typedef size_t (*proto_t) (const CHAR *, const CHAR *);
Packit Service 82fcde
size_t SIMPLE_STRCSPN (const CHAR *, const CHAR *);
Packit Service 82fcde
size_t STUPID_STRCSPN (const CHAR *, const CHAR *);
Packit Service 82fcde
Packit Service 82fcde
IMPL (STUPID_STRCSPN, 0)
Packit Service 82fcde
IMPL (SIMPLE_STRCSPN, 0)
Packit Service 82fcde
IMPL (STRCSPN, 1)
Packit Service 82fcde
Packit Service 82fcde
size_t
Packit Service 82fcde
SIMPLE_STRCSPN (const CHAR *s, const CHAR *rej)
Packit Service 82fcde
{
Packit Service 82fcde
  const CHAR *r, *str = s;
Packit Service 82fcde
  CHAR c;
Packit Service 82fcde
Packit Service 82fcde
  while ((c = *s++) != '\0')
Packit Service 82fcde
    for (r = rej; *r != '\0'; ++r)
Packit Service 82fcde
      if (*r == c)
Packit Service 82fcde
	return s - str - 1;
Packit Service 82fcde
  return s - str - 1;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
size_t
Packit Service 82fcde
STUPID_STRCSPN (const CHAR *s, const CHAR *rej)
Packit Service 82fcde
{
Packit Service 82fcde
  size_t ns = STRLEN (s), nrej = STRLEN (rej);
Packit Service 82fcde
  size_t i, j;
Packit Service 82fcde
Packit Service 82fcde
  for (i = 0; i < ns; ++i)
Packit Service 82fcde
    for (j = 0; j < nrej; ++j)
Packit Service 82fcde
      if (s[i] == rej[j])
Packit Service 82fcde
	return i;
Packit Service 82fcde
  return i;
Packit Service 82fcde
}
Packit Service 82fcde
Packit Service 82fcde
#undef CHAR
Packit Service 82fcde
#undef STRLEN
Packit Service 82fcde
#include "bench-strpbrk.c"