simple-benchmark.js 743 B

1234567891011121314151617181920212223242526272829
  1. 'use strict';
  2. const { Piscina } = require('..');
  3. const { resolve } = require('path');
  4. async function simpleBenchmark ({ duration = 10000 } = {}) {
  5. const pool = new Piscina({ filename: resolve(__dirname, 'fixtures/add.js') });
  6. let done = 0;
  7. const results = [];
  8. const start = process.hrtime.bigint();
  9. while (pool.queueSize === 0) {
  10. results.push(scheduleTasks());
  11. }
  12. async function scheduleTasks () {
  13. while ((process.hrtime.bigint() - start) / 1_000_000n < duration) {
  14. await pool.runTask({ a: 4, b: 6 });
  15. done++;
  16. }
  17. }
  18. await Promise.all(results);
  19. return done / duration * 1e3;
  20. }
  21. simpleBenchmark().then((opsPerSecond) => {
  22. console.log(`opsPerSecond: ${opsPerSecond} (with default taskQueue)`);
  23. });