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);
23 cs += (int)strstr(haystack, needle);
29 void bench_string_strstr1(int N) {
30 bstrstr(N, "abcdefghijklmnopqrstuvwxyz");
32 void bench_string_strstr2(int N) {
33 bstrstr(N, "azbycxdwevfugthsirjqkplomn");
35 void bench_string_strstr3(int N) {
36 bstrstr(N, "aaaaaaaaaaaaaacccccccccccc");
38 void bench_string_strstr4(int N) {
39 bstrstr(N, "aaaaaaaaaaaaaaaaaaaaaaaaac");
41 void bench_string_strstr5(int N) {
42 bstrstr(N, "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaac");
45 void bench_string_memset(int N) {
46 char *buf = malloc(LEN);
50 memset(buf+i, i, LEN-i);
54 void bench_string_strchr(int N) {
55 char *buf = malloc(LEN);
59 memset(buf, 'a', LEN);
65 cs ^= (int)strchr(buf, 'b');
71 void bench_string_strlen(int N) {
72 char *buf = malloc(LEN);
76 memset(buf, 'a', LEN-1);