Last active
May 26, 2019 14:44
-
-
Save prmishra/d097c0a4ea85338bb7489df433734712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var list = process.argv.slice(2); | |
var sum = 0; | |
var add = function() { | |
if (list.length === 0) { | |
console.log('sum ' + sum); | |
} | |
var item = list.pop(); | |
if (item) { | |
sum += Number(item); | |
add(); | |
} | |
}; | |
var hrTime = process.hrtime() | |
start_time = hrTime[0] * 1000000 + hrTime[1] / 1000 | |
add(); | |
var hrTime = process.hrtime() | |
end_time = hrTime[0] * 1000000 + hrTime[1] / 1000 | |
console.log('time ' + Math.round(end_time - start_time)) | |
// node script.js 1 2 3 4 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
var list = process.argv.slice(2);
var sum = 0;
var add = function () {
if (list.length === 0) {
console.log('sum ' + sum);
}
};
var hrTime = process.hrtime()
start_time = hrTime[0] * 1000000 + hrTime[1] / 1000
add();
var hrTime = process.hrtime()
end_time = hrTime[0] * 1000000 + hrTime[1] / 1000
console.log('time ' + Math.round(end_time - start_time) / 1000)