samedi 27 janvier 2018

If/else Performance

I'm trying to figure out the difference in CPU usage and performance comparing two if/else statements, take the following functions

function f(x):
  if(condition) return true;
  else return false;

function f'(x):
  if(condition) return true;
  return false;

The purpose of the function is not important, of course in both cases you want to return true if the 'if' is true, otherwise return false.

Both pieces of code do the same thing, I'm thinking with regards to performance and CPU usage, would there be any difference between these two programs when removing the else statement and using the sequential execution to do the 'else' instead, or when compiled would the difference just be lost?

Aucun commentaire:

Enregistrer un commentaire