Last change
on this file since 6a80231 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago |
initial commit
|
-
Property mode
set to
100644
|
File size:
718 bytes
|
Line | |
---|
1 | 'use strict';
|
---|
2 | const { Piscina } = require('..');
|
---|
3 | const { resolve } = require('path');
|
---|
4 |
|
---|
5 | async function simpleBenchmark ({ duration = 10000 } = {}) {
|
---|
6 | const pool = new Piscina({ filename: resolve(__dirname, 'fixtures/add.js') });
|
---|
7 | let done = 0;
|
---|
8 |
|
---|
9 | const results = [];
|
---|
10 | const start = process.hrtime.bigint();
|
---|
11 | while (pool.queueSize === 0) {
|
---|
12 | results.push(scheduleTasks());
|
---|
13 | }
|
---|
14 |
|
---|
15 | async function scheduleTasks () {
|
---|
16 | while ((process.hrtime.bigint() - start) / 1_000_000n < duration) {
|
---|
17 | await pool.runTask({ a: 4, b: 6 });
|
---|
18 | done++;
|
---|
19 | }
|
---|
20 | }
|
---|
21 |
|
---|
22 | await Promise.all(results);
|
---|
23 |
|
---|
24 | return done / duration * 1e3;
|
---|
25 | }
|
---|
26 |
|
---|
27 | simpleBenchmark().then((opsPerSecond) => {
|
---|
28 | console.log(`opsPerSecond: ${opsPerSecond}`);
|
---|
29 | });
|
---|
Note:
See
TracBrowser
for help on using the repository browser.