making function slowdown the speed of program ?

Any other suggestions to make to code faster in CPP. In terms of compidative programming , using printf /scanf in place of cout/cin is a good idea? David Carroll & bunny & Haris

10/23/2019 4:38:09 AM


7 Answers

New Answer


Things like doing a binary search rather than a linear search on a sorted list will help reduce time complexity.


Inlining functions, use of register variables also helps.


Program speed depends on many things. First and foremost have you handled everything correctly? Secondly it depends on algorithm complexity. e.g. if you put a triple for loop your program will be slower than if you have a single for loop.


You might also be able to tweak the optimisation levels of the compiler.


Speed or time taken by a program depends on how you implement it, there may be several methods (algorithms) to perform the same task, one algorithm is considered better than the other if it has better time or space complexity (Though we usually prefer time over space, depends upon what you want). As for your question, if your function is small enough then the time taken in calling the function may be more than the time taken by the actual function, in that case you can use inline functions, though usually you may not need them. Printf and scanf are certainly a lot faster than cin / cout but if you use ios_base sync_with_stdio(false); cin.tie(null); cout.tie(null) ; With this cin and cout will work as fast as printf/scanf, (this is what you need to use when a question says "you may need to use fast input output" in c++). PS: I am sort of a competitive programmer myself (though i am not that good yet).


bufftowel tanks for info


Thanks very much 😉