Strange results

I have a generated lexer. The lexer makes a callback in the parameter and calls it every time a match is found. Callback prototype:

void(const char *matchBegin, const char *matchEnd, unsigned matchId); 

I am testing it with two callbacks:

Empty callback:

 [] (const char *, const char *, unsigned) {} 

Counter callback increment:

 [&counter] (const char *, const char *, unsigned id) { counter += id; } 

Below are the measurements for entering 100 MB (there is no difference between the programs, except for these callbacks):

gcc 5.2 empty calback: Avg: 582.3ms, StdDev: 11.3ms (run 20 times)

gcc 5.2 increment callback: Avg: 396.6ms, StdDev: 1.68ms (run 20 times)

clang 3.7 empty calback: 402ms

clang 3.7 increment callback: 577ms

My intuition is that an extra increment operation should cost us time. Apparently this is not the case with gcc. Can someone explain why?

EDIT: @Joachim: lexer accepts any function object in a parameter:

 template <typename M, typename Action> inline void tokenize(const M &stateMachine, const char *&begin, const char *end, Action action); 

Time is automatically measured by gtest. One test is in progress. The generation of the state apparatus is not taken into account.

+5
source share

Source: https://habr.com/ru/post/1235779/


All Articles