Hi codeforces , I was arguing with my friend about which is the best type of functions , so we had to try every type of functions in c++ .
I tried all three types of functions on some recursion problems and I got the following result :
Time complexity :
- normal function : it was the fastest .
- lambda function : it was slower than the normal function by 20 ms .
- std function : it was slower than the previous two by 200 ms .
Memory complexity :
- std function : was the best .
- normal function : was worse than std function by 30000 kb (maybe that's because of changing the arrays' identification to a global scope with const length)
- lambda : was exactly the same as the normal function (without using global scope) .
this result was satisfying but when I tried on other problems a contradictory result appeared :
Time complexity :
- normal function : it was the fastest .
- std function : it was slower than the normal function by 100 ms .
- lambda function : it was slower than std by 30 ms .
Memory complexity :
- std function : was the best .
- lambda : was worse than std function by 100 kb (nothing) .
- normal function : was worse than std function by 6000 kb (maybe that's because of changing the arrays' identification to a global scope with const length) .
so I was wondering what is the best type of functions for time complexity and memory complexity (depending on assembly and how many additional assembly lines for every type) cause even reading the documentation wasn't useful .
thanks in advance .
the unexpected result submission links :
std : 363673434 lambda : 363682810 normal : 363673624
Полный текст и комментарии »