+ 3

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

23rd Oct 2019, 4:38 AM
karangreat
karangreat - avatar
7 Respostas
+ 9
Things like doing a binary search rather than a linear search on a sorted list will help reduce time complexity.
23rd Oct 2019, 6:58 AM
Sonic
Sonic - avatar
+ 7
Inlining functions, use of register variables also helps.
23rd Oct 2019, 6:59 AM
Sonic
Sonic - avatar
+ 6
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.
23rd Oct 2019, 4:43 AM
Haris
Haris - avatar
+ 6
You might also be able to tweak the optimisation levels of the compiler.
23rd Oct 2019, 7:00 AM
Sonic
Sonic - avatar
+ 4
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).
23rd Oct 2019, 4:35 PM
bufftowel
bufftowel - avatar
+ 4
bufftowel tanks for info
23rd Oct 2019, 11:34 PM
karangreat
karangreat - avatar
+ 3
Thanks very much 😉
23rd Oct 2019, 8:38 AM
karangreat
karangreat - avatar