From c636bbfd00ca4e9cf7d4269be4647831fc61ae3f Mon Sep 17 00:00:00 2001 From: haad Date: Fri, 25 Nov 2016 15:50:42 +0100 Subject: [PATCH] Fix benchmark --- examples/benchmark.js | 46 +++++++++++++++++++++---------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/examples/benchmark.js b/examples/benchmark.js index d6543ac..3453130 100644 --- a/examples/benchmark.js +++ b/examples/benchmark.js @@ -20,29 +20,29 @@ const queryLoop = (db) => { } // Start -let run = (() => { - IpfsDaemon({ IpfsDataDir: '/tmp/orbit-db-benchmark' }) - .then((res) => { - const orbit = new OrbitDB(res.ipfs, 'benchmark') - const db = orbit.eventlog('orbit-db.benchmark') +console.log("Starting...") - // Metrics output - setInterval(() => { - seconds ++ - if(seconds % 10 === 0) { - console.log(`--> Average of ${lastTenSeconds/10} q/s in the last 10 seconds`) - if(lastTenSeconds === 0) - throw new Error("Problems!") - lastTenSeconds = 0 - } - console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds`) - queriesPerSecond = 0 - }, 1000) +const ipfs = new IpfsDaemon({ IpfsDataDir: '/tmp/orbit-db-benchmark' }) - // Start the main loop - queryLoop(db) - }) - .catch((e) => console.error(e)) -})() +ipfs.on('error', (err) => console.error(err)) -module.exports = run +ipfs.on('ready', () => { + const orbit = new OrbitDB(ipfs, 'benchmark') + const db = orbit.eventlog('orbit-db.benchmark') + + // Metrics output + setInterval(() => { + seconds ++ + if(seconds % 10 === 0) { + console.log(`--> Average of ${lastTenSeconds/10} q/s in the last 10 seconds`) + if(lastTenSeconds === 0) + throw new Error("Problems!") + lastTenSeconds = 0 + } + console.log(`${queriesPerSecond} queries per second, ${totalQueries} queries in ${seconds} seconds`) + queriesPerSecond = 0 + }, 1000) + + // Start the main loop + queryLoop(db) +})