Benchmark IF x Return

In this example below you will see how to do a Benchmark IF x Return with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by felvieira, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright felvieira ©

Technologies

  • HTML
  • JavaScript
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>Benchmark IF x Return</title>
  
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/5.0.0/normalize.min.css">

  
  
  
</head>

<body>

  
  
  

    <script  src="js/index.js"></script>




</body>

</html>

/*Downloaded from https://www.codeseek.co/felvieira/benchmark-if-x-return-EEQBJO */
function KubaBaixinhoRet1(){
	if(kuba > 1,60){
		kuba=alto;
		return;
	}
kuba = baixo;
}

function KubaBaixinhoRet2(){
	kuba = baixo;
	if(kuba > 1,60){
		kuba=alto;
	}
	
	return kuba
}

function KubaBaixinhoElse(){
	if(kuba > 1,60){
		kuba=alto;
	} else {
		kuba = baixo;
	}
}


var bench = function (method, iterations, args, context) {

    var time = 0;
    var timer = function (action) {
        var d = Date.now();
        if (time < 1 || action === 'start') {
            time = d;
            return 0;
        } else if (action === 'stop') {
            var t = d - time;
            time = 0;    
            return t;
        } else {
            return d - time;    
        }
    };

    var result = [];
    var i = 0;
    timer('start');
    while (i < iterations) {
        result.push(method.apply(context, args));
        i++;
    }

    var execTime = timer('stop');

    if ( typeof console === "object") {
        console.log("Mean execution time was: ", execTime / iterations);
        console.log("Sum execution time was: ", execTime);
        console.log("Result of the method call was:", result[0]);
    }

    return execTime;  
};

Comments