Last active
March 18, 2020 01:06
-
-
Save dsetzer/5c68c405a710742ccd30dc4a37c94c46 to your computer and use it in GitHub Desktop.
Testing async throughput in bustadice
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
let betCount = 0; | |
let totalOut = 0; | |
let totalIn = 0; | |
let queueSize = 200 | |
let queue = new Array(queueSize); | |
let running = true; | |
const doResult = async function (context, result) { | |
totalIn++; | |
context.log(`Current Bets IN/OUT ${totalIn}/${totalOut} | Total Bets ${betCount}`); | |
} | |
const main = async function (context) { | |
const startTime = Date.now() | |
while (running) { | |
const cycleStart = Date.now(); | |
for (let i = 0; i < queueSize; i++) { | |
queue[i] = context.bet(100, 2), betCount++, totalOut++; | |
await sleep(1); | |
} | |
const genTime = Date.now(); | |
if (running) { | |
await Promise.all(queue.map(p => p.catch(e => e))).then(async (results) => { await results.forEach(result => doResult(context, result)) }); | |
} | |
const cycleEnd = Date.now(); | |
context.log(`Cycle efficiency at ${(queueSize / (genTime - startTime)) * 1000} + ${(queueSize / (cycleEnd - genTime)) * 1000} bets per second.`) | |
} | |
const endTime = Date.now(); | |
context.log(`Total script runtime ${(endTime - startTime) / 60000} minutes.`) | |
} | |
function sleep(ms) { | |
return new Promise(resolve => setTimeout(resolve, ms)); | |
} | |
await this.log(`Starting script at ${queueSize} queue size`) | |
await main(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment