Skip to content

Instantly share code, notes, and snippets.

@serverwentdown
Created May 8, 2014 12:47
Show Gist options
  • Save serverwentdown/8318445d4642b0b4929c to your computer and use it in GitHub Desktop.
Save serverwentdown/8318445d4642b0b4929c to your computer and use it in GitHub Desktop.
Typing thingy...
process.stdin.setEncoding('utf8');
var str = "File I/O is provided by simple wrappers around standard POSIX functions. To use this module do require('fs'). All the methods have asynchronous and synchronous forms.";
console.log("Hello! ");
console.log("Type this out and press return: ");
console.log("--------------------------");
console.log(str);
console.log("--------------------------");
process.stdout.write("Press enter to start: ");
var starttime, difftime;
var start = false;
process.stdin.on('data', function (chunk) {
if (start == false) {
start = true;
starttime = process.hrtime();
}
else {
if (chunk.indexOf(str) == 0) {
difftime = process.hrtime(starttime);
var nano = difftime[0] * 1e9 + difftime[1];
console.log("You took " + nano + " nanoseconds to type " + str.length + " characters. ");
console.log("That is aproximately " + ((str.length + 1) / nano * 1e9) + " char/sec, " + (nano / 1e6 / (str.length + 1)) + " ms/char. ");
process.exit();
}
else {
process.stdout.write("You have errors in your typing, press enter to try again: ");
start = false;
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment