summary refs log tree commit diff
path: root/benchtests/bench-strcspn.c
diff options
context:
space:
mode:
authorSiddhesh Poyarekar <siddhesh@redhat.com>2013-06-04 16:48:56 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2013-06-11 15:08:13 +0530
commit9702047480d9002522936c5e1e1ebe16f696880d (patch)
tree9b37e288e4d57012a6186c280fd8837deca6dd4c /benchtests/bench-strcspn.c
parentc1f75dc386d533806d29b7e94118363a7b50eed8 (diff)
downloadglibc-9702047480d9002522936c5e1e1ebe16f696880d.tar.gz
glibc-9702047480d9002522936c5e1e1ebe16f696880d.tar.xz
glibc-9702047480d9002522936c5e1e1ebe16f696880d.zip
Copy over string performance tests into benchtests
Copy over already existing string performance tests into benchtests.
Bits not related to performance measurements have been omitted.
Diffstat (limited to 'benchtests/bench-strcspn.c')
-rw-r--r--benchtests/bench-strcspn.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/benchtests/bench-strcspn.c b/benchtests/bench-strcspn.c
new file mode 100644
index 0000000000..22b3b84957
--- /dev/null
+++ b/benchtests/bench-strcspn.c
@@ -0,0 +1,59 @@
+/* Measure strcspn functions.
+   Copyright (C) 2013 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#define STRPBRK_RESULT(s, pos) (pos)
+#define RES_TYPE size_t
+#define TEST_MAIN
+#define TEST_NAME "strcspn"
+#include "bench-string.h"
+
+typedef size_t (*proto_t) (const char *, const char *);
+size_t simple_strcspn (const char *, const char *);
+size_t stupid_strcspn (const char *, const char *);
+
+IMPL (stupid_strcspn, 0)
+IMPL (simple_strcspn, 0)
+IMPL (strcspn, 1)
+
+size_t
+simple_strcspn (const char *s, const char *rej)
+{
+  const char *r, *str = s;
+  char c;
+
+  while ((c = *s++) != '\0')
+    for (r = rej; *r != '\0'; ++r)
+      if (*r == c)
+	return s - str - 1;
+  return s - str - 1;
+}
+
+size_t
+stupid_strcspn (const char *s, const char *rej)
+{
+  size_t ns = strlen (s), nrej = strlen (rej);
+  size_t i, j;
+
+  for (i = 0; i < ns; ++i)
+    for (j = 0; j < nrej; ++j)
+      if (s[i] == rej[j])
+	return i;
+  return i;
+}
+
+#include "bench-strpbrk.c"