On 23.11.2015 19:05, Yann Ylavic wrote: > while (ucharmap[*ps1] == ucharmap[*ps2++]) { > if (*ps1++ == '\0') { > return (0); > } > } > return (ucharmap[*ps1] - ucharmap[*--ps2]); Is there really a gain in inc- and decrementing this way? Would not it be easier to read with the explicit increments -- and, incidentally, no decrements at all?
while (ucharmap[*ps1] == ucharmap[*ps2]) { if (*ps1 == '\0') { return (0); } ++ps1; ++ps2; } return (ucharmap[*ps1] - ucharmap[*ps2]); > We don't care about the whole process time and other counters. That's certainly true. But, then, why bother with building time-counter into the test at all -- instead of simply relying on time(1)? But something is still not right -- the result (for either of the methods) can depend on the number of iterations (!!): ./strncasecmp 1 27 aCaa Ac 2 Optimized (nb=27, len=2) time = 0.000001 : res = 32 ./strncasecmp 1 26 aCaa Ac 2 Optimized (nb=26, len=2) time = 0.000001 : res = 0 ./strncasecmp 0 27 aCaa Ac 2 <string.h> (nb=27, len=2) time = 0.000003 : res = 32 ./strncasecmp 0 26 aCaa Ac 2 <string.h> (nb=26, len=2) time = 0.000003 : res = 0 Using clang on FreeBSD/amd64 here. Yours, -mi