Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

parsed = http_parser_execute(parser, &settings_null, buf, strlen(buf));

assert(parsed == strlen(buf));

He's calling strlen(buf) twice here. There's no guarantee that this is optimized at compile time. Usually len of buf is determined from read/recv system calls and for a fair comparison strlen should be removed here.



No difference even though I ran the benchmark again after removing the line.


Interesting. I was expecting at least cpu branch improvements given the lack of assert.


Also use gettimeofday() instead of clock(), because you don't know how far into the second you are at the time it's called.


Any good compiler will optimize that out. (Actually, even a bad compiler will optimize that out... it's a really easy optimization).


assert only runs in debug mode anyway.


It runs unless NDEBUG is defined, which the author did not do according to his methodology. Anyway I looked at the assembly output and strlen() is optimized away.


I really do not like when bad habits are encouraged by the optimizer.



"Forcing a definition of the name NDEBUG, either from the compiler command line or with the preprocessor control statement #define NDEBUG ahead of the #include <assert.h> statement, shall stop assertions from being compiled into the program"




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: