8 static int bstrstr(int N, const char *needle) {
9 size_t l = strlen(needle);
13 char *haystack = malloc(l * cnt + 1);
15 for (i=0; i<cnt-1; i++) {
16 memcpy(haystack + l*i, needle, l);
17 haystack[l*i+l-1] ^= 1;
19 memcpy(haystack + l*i, needle, l+1);
22 cs += (int)strstr(haystack, needle);
28 void bench_string_strstr1(int N) {
29 bstrstr(N, "abcdefghijklmnopqrstuvwxyz");
31 void bench_string_strstr2(int N) {
32 bstrstr(N, "azbycxdwevfugthsirjqkplomn");
34 void bench_string_strstr3(int N) {
35 bstrstr(N, "aaaaaaaaaaaaaacccccccccccc");
37 void bench_string_strstr4(int N) {
38 bstrstr(N, "aaaaaaaaaaaaaaaaaaaaaaaaac");
40 void bench_string_strstr5(int N) {
41 bstrstr(N, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac");
44 void bench_string_memset(int N) {
45 char *buf = malloc(LEN);
49 memset(buf+i, i, LEN-i);
53 void bench_string_strchr(int N) {
54 char *buf = malloc(LEN);
58 memset(buf, 'a', LEN);
64 cs ^= (int)strchr(buf, 'b');
70 void bench_string_strlen(int N) {
71 char *buf = malloc(LEN);
75 memset(buf, 'a', LEN-1);