Add optimized version of memchr
Created by: matijaskala
This is what musl does - read 8 bytes at a time until a match is found
Merge request reports
Activity
Created by: matijaskala
#include <string.h> #include <stdio.h> #include <time.h> void* memchr1 (const void* s, int c, size_t n); void* memchr2 (const void* s, int c, size_t n); char s[1000000]; int main () { memset (s, 0, sizeof(s)); s[999999] = 1; struct timespec t1, t2, t3, t4; clock_gettime (CLOCK_REALTIME, &t1); for (int i = 0; i < 100; i++) memchr1 (s, 1, sizeof(s)); clock_gettime (CLOCK_REALTIME, &t2); clock_gettime (CLOCK_REALTIME, &t3); for (int i = 0; i < 100; i++) memchr2 (s, 1, sizeof(s)); clock_gettime (CLOCK_REALTIME, &t4); printf ("%ld\n%ld\n", (t2.tv_sec-t1.tv_sec)*1000000000l + t2.tv_nsec - t1.tv_nsec, (t4.tv_sec-t3.tv_sec)*1000000000l + t4.tv_nsec - t3.tv_nsec); }
# ./a.out 66656610 10906751
Created by: matijaskala
Offset Speedup 1 -41.72% 2 -33.13% 3 -24.33% 4 -31.56% 5 -12.84% 6 -15.76% 7 -4.64% 8 55.62% 9 60.17% 10 64.52% 12 65.68% 14 63.10% 16 129.31% 18 149.42% 20 128.14% 22 138.40% 24 173.81% 26 164.67% 28 169.54% 30 152.82% 32 331.13% 34 222.47% 36 205.11% 38 186.38% 40 273.06%
Please register or sign in to reply