Skip to content

Instantly share code, notes, and snippets.

@mmarchini
Created September 26, 2020 23:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmarchini/5da624b8c62fe1ecfe4944726a3cf4c6 to your computer and use it in GitHub Desktop.
Save mmarchini/5da624b8c62fe1ecfe4944726a3cf4c6 to your computer and use it in GitHub Desktop.
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()
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Display the source blob
Display the rendered blob
Raw
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment