+ 2
Give me an idea about code optimisation.
7 Answers
+ 4
Code optimisation is the method in which code will be optimize and it will make code easy to understand..
+ 4
https://www.google.co.in/url?sa=t&source=web&rct=j&url=https://medium.com/humans-create-software/how-do-i-learn-to-write-simpler-more-efficient-code-with-fewer-lines-da0fe693146e&ved=0ahUKEwiE5JrHpPvXAhXLu7wKHdP_CKQQFgg7MAQ&usg=AOvVaw1MgAvjudSZ5Y0QBruaCMD4
https://www.google.co.in/url?sa=t&source=web&rct=j&url=https://www.codeproject.com/Articles/6154/Writing-Efficient-C-and-C-Code-Optimization&ved=0ahUKEwiE5JrHpPvXAhXLu7wKHdP_CKQQFgg-MAU&usg=AOvVaw1LHc62f3i_1gy9m5BpcdJz
these 2 link will might give u ur answer..
+ 4
Lets look at the following code:
x = 5 + 13 * 3;
y = 7 + 13 * 3;
Optimized code would see the '13 * 3' and only calculate it once using the result twice. Non-optimized code calculates it twice.
+ 4
Not optimized (inline, repeated checking):
-------------------------
code
code
if(navigator.vibrate) {
navigator.vibrate(500);
}
// verbose, repeat many times, check each time
More optimized (less sugar/clutter, same checking)
---------------------------
function vib(howlong){
if(navigator.vibrate) navigator.vibrate(howlong);
}
code
code
vib(500) // existence still tested each call
Even more optimized (1 check, never again -- this, or a lambda)
------------------------------
var vib = function(){} // default null function
if(navigator.vibrate)
vib = function(howlong){navigator.vibrate(howlong)}
code
code
vib(500); // No more tests; it just does the right thing
+ 3
And, as @John mentions, calculation duplication. In the 3D->2D projection formulas at Wikipedia, you can collapse ~50+% of the formulas into reused calculations:
https://en.wikipedia.org/wiki/3d_projection#Perspective_projection
Starting at "Alternatively, without using matrices..." those formulas have several duplicated items, e.g. (SzY + CzX) ... but as you pull back, there are more. (Yes, this contains trigonometry, but reduction is no worse than algebra, which you do in code already: int a = x+y;).
+ 2
thank u...
+ 1
yeah...ok..can u explain how to minimize the code to simpler...