Created
September 26, 2020 23:17
-
-
Save mmarchini/5da624b8c62fe1ecfe4944726a3cf4c6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const total = 200000 | |
const batch = 32768 | |
const tokens1 = [], tokens2 = [] | |
const one = () => { | |
tokens1.push(0); | |
if (tokens1.length > 0 && tokens2.length > 0) { | |
tokens1.splice(0, 1); | |
tokens2.splice(0, 1); | |
} | |
} | |
const two = () => { | |
tokens2.push(0); | |
if (tokens1.length > 0 && tokens2.length > 0) { | |
tokens1.splice(0, 1); | |
tokens2.splice(0, 1); | |
} | |
} | |
console.log(process.version) | |
console.time() | |
for (let t = 0; t < total; t += batch) { | |
for (let i = 0; i < batch; i++) one() | |
for (let i = 0; i < batch; i++) two() | |
} | |
console.timeEnd() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment