-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathf_boot.txt
12 lines (11 loc) · 1.48 KB
/
f_boot.txt
1
2
3
4
5
6
7
8
9
10
11
12
Things for Faster C++ code Executions:
-> Avoid cin/cout, use scanf/printf at any cost. Cin/Cout are extremely time consuming functions. If you want even better performance use getchar_unlocked. This(http://abhisharlives.blogspot.com/2012/06/really-fast-io-methods-for-programming.html) article explains it pretty well.
-> Try using global arrays instead of passing them to a function. Passing array as a pointer to a function is efficient, but declaring a global array and directly using it is even better. And of course, avoid passing arguments by value. Similarly, if you are passing a vector to a function, use a constant reference.
-> Use macros and Inline functions. Calling a function involves overhead which can be avoided by using macros or inline functions, but you need to very careful.
-> Use pre-increment instead of post-increment. Post increment is designed to return the original object, which might force the compiler to create another copy of the object in some cases.
-> Use left/right shift in place of division/multiplication by 2. For example you can replace x = x*4 by x = x<<2.
-> Use heap memory only when absolutely necessary. Dynamic initialization and deallocations is costly.
-> Use multiple arrays instead of one large array.
-> Use unordered_map instead of the usual stl map. Use std::sort instead of qsort.
-> In an if else block, make sure that the condition in if block, is the one that is more likely to be true.
-> Always use '\n' to change the line. endl takes a lot of time.