Gentoo Linux and VIM worshiper, C developer, network protocol dissector implementer,socket/network programmer, recently entered the embedded world, hater of buzzwords and made up titles
I wrote this too fast without even thinking too much, so once again, I appreciate your comment. Anyway, I know that inlining helps, but speed wasn't on my priority list for this challenge. :)
Here are my results:
Your code: ~550 nsec
My code: ~1140 nsec
Thumbs up for faster code.
P.S.
I suspected that strlen might be the culprit, and I was right.
If I change the code like this, I get results similar to yours, around 500 nsec more/less
staticboolcount_xo(constchar*d,size_tl){// null pointerif(!d)returntrue;// no dataif(!l)returntrue;// res countersunsignedxc=0,oc=0;// mid pointunsignedmp=l/2,rm=l%2;// check for 88 (X) and 79 (O)// O(N/2)for(unsignedi=0,j=l-1;i<mp;i++,j--){// X counterxc+=check_x(d[i])+check_x(d[j]);// O counteroc+=check_o(d[i])+check_o(d[j]);}// remainderif(rm){// X counterxc+=check_x(d[mp+1]);// O counteroc+=check_o(d[mp+1]);}// resreturnxc==oc;}
Gentoo Linux and VIM worshiper, C developer, network protocol dissector implementer,socket/network programmer, recently entered the embedded world, hater of buzzwords and made up titles
I wrote this too fast without even thinking too much, so once again, I appreciate your comment. Anyway, I know that inlining helps, but speed wasn't on my priority list for this challenge. :)
Here are my results:
Your code: ~550 nsec
My code: ~1140 nsec
Thumbs up for faster code.
P.S.
I suspected that
strlen
might be the culprit, and I was right.If I change the code like this, I get results similar to yours, around 500 nsec more/less
Nice. I didn’t inline for speed, but for compactness, so that people don’t say C is too complicated, so verbose, etc. :-)
C is my baby, just started embedded C on SBCs, mostly arm 32bit. And people will always say that 🤣👍