Created
November 18, 2019 05:03
-
-
Save gngenius02/3c842e5f46d151f730b012037ecd596c 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
//call the module | |
const looper = require('./looper') | |
//create an object to pass to the loop module | |
const loopOptions = { | |
fn: () => Math.random(), | |
max: 1e9 | |
} | |
looper(loopOptions); | |
->//{ 'runtime(sec)': 29.4098592 } |
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
module.exports = function(object) { | |
const { max = 1000000000n, fn } = object; | |
let counter = 0; | |
let running = true; | |
Error.stackTraceLimit = 100; | |
const A = (fn) => { | |
fn(); | |
flipper = B; | |
}; | |
const B = (fn) => { | |
fn(); | |
flipper = A; | |
}; | |
let flipper = B; | |
const then = process.hrtime.bigint(); | |
do { | |
counter++; | |
if (counter > max) { | |
const now = process.hrtime.bigint(); | |
const nanos = now - then; | |
console.log({ 'runtime(sec)': Number(nanos) / 1000000000.0 }); | |
running = false; | |
} | |
flipper(fn); | |
continue; | |
} while (running); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment