summaryrefslogtreecommitdiff
path: root/string.c
blob: 158b828b8593df587e09d4580aca12da406b1316 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define BUFLEN 500000

size_t b_string_strstr(void *dummy)
{
	const char *needle = dummy;
	size_t l = strlen(needle);
	size_t i;
	size_t cnt = 10000;
	size_t cs = 0;
	char *haystack = malloc(l * cnt + 1);
	for (i=0; i<cnt-1; i++) {
		memcpy(haystack + l*i, needle, l);
		haystack[l*i+l-1] ^= 1;
	}
	memcpy(haystack + l*i, needle, l+1);
	for (i=0; i<50; i++) {
		haystack[0]^=1;
		cs += (int)strstr(haystack, needle);
	}
	free(haystack);
	return cs;
}

size_t b_string_memset(void *dummy)
{
	char *buf = malloc(BUFLEN);
	size_t i;
	for (i=0; i<100; i++)
		memset(buf+i, i, BUFLEN-i);
	free(buf);
	return 0;
}

size_t b_string_strchr(void *dummy)
{
	char *buf = malloc(BUFLEN);
	size_t i;
	size_t cs;
	memset(buf, 'a', BUFLEN);
	buf[BUFLEN-1] = 0;
	buf[BUFLEN-2] = 'b';
	for (i=0; i<100; i++) {
		buf[i] = '0'+i%8;
		cs += (int)strchr(buf, 'b');
	}
	free(buf);
	return cs;
}

size_t b_string_strlen(void *dummy)
{
	char *buf = malloc(BUFLEN);
	size_t i;
	size_t cs = 0;

	memset(buf, 'a', BUFLEN-1);
	buf[BUFLEN-1] = 0;
	for (i=0; i<100; i++) {
		buf[i] = '0'+i%8;
		cs += strlen(buf);
	}
	free(buf);
	return cs;
}