This commit is contained in:
CHEVALLIER Abel
2025-11-13 16:23:22 +01:00
parent de9c515a47
commit cb235644dc
34924 changed files with 3811102 additions and 0 deletions

2
node_modules/piscina/benchmark/fixtures/add.js generated vendored Normal file
View File

@@ -0,0 +1,2 @@
'use strict';
module.exports = ({ a, b }) => a + b;

View File

@@ -0,0 +1,41 @@
const { Bench } = require('tinybench');
const { Piscina, FixedQueue, ArrayTaskQueue } = require('..');
const { resolve } = require('node:path');
const QUEUE_SIZE = 100_000;
const bench = new Bench({ time: 100, warmup: true });
bench
.add('Piscina with ArrayTaskQueue', async () => {
const queue = new ArrayTaskQueue();
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/add.js'),
taskQueue: queue
});
const tasks = [];
for (let i = 0; i < QUEUE_SIZE; i++) {
tasks.push(pool.run({ a: 4, b: 6 }));
}
await Promise.all(tasks);
await pool.destroy();
})
.add('Piscina with FixedQueue', async () => {
const queue = new FixedQueue();
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/add.js'),
taskQueue: queue
});
const tasks = [];
for (let i = 0; i < QUEUE_SIZE; i++) {
tasks.push(pool.run({ a: 4, b: 6 }));
}
await Promise.all(tasks);
await pool.destroy();
});
(async () => {
await bench.run();
console.table(bench.table());
})();

32
node_modules/piscina/benchmark/queue-comparison.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
const { Bench } = require('tinybench');
const { ArrayTaskQueue, FixedQueue } = require('..');
const QUEUE_SIZE = 100_000;
const bench = new Bench({ time: 100, warmup: true });
bench
.add('ArrayTaskQueue full push + full shift', async () => {
const queue = new ArrayTaskQueue();
for (let i = 0; i < QUEUE_SIZE; i++) {
queue.push(i);
}
for (let i = 0; i < QUEUE_SIZE; i++) {
queue.shift();
}
})
.add('FixedQueue full push + full shift', async () => {
const queue = new FixedQueue();
for (let i = 0; i < QUEUE_SIZE; i++) {
queue.push(i);
}
for (let i = 0; i < QUEUE_SIZE; i++) {
queue.shift();
}
});
(async () => {
await bench.run();
console.table(bench.table());
})();

View File

@@ -0,0 +1,29 @@
'use strict';
const { Piscina } = require('../dist');
const { resolve } = require('path');
async function simpleBenchmark ({ duration = 10000 } = {}) {
const pool = new Piscina({ filename: resolve(__dirname, 'fixtures/add.js'), atomics: 'async' });
let done = 0;
const results = [];
const start = process.hrtime.bigint();
while (pool.queueSize === 0) {
results.push(scheduleTasks());
}
async function scheduleTasks () {
while ((process.hrtime.bigint() - start) / 1_000_000n < duration) {
await pool.run({ a: 4, b: 6 });
done++;
}
}
await Promise.all(results);
return done / duration * 1e3;
}
simpleBenchmark().then((opsPerSecond) => {
console.log(`opsPerSecond: ${opsPerSecond} (with default taskQueue)`);
});

View File

@@ -0,0 +1,33 @@
'use strict';
const { Piscina, FixedQueue } = require('..');
const { resolve } = require('path');
async function simpleBenchmark ({ duration = 10000 } = {}) {
const pool = new Piscina({
filename: resolve(__dirname, 'fixtures/add.js'),
taskQueue: new FixedQueue()
});
let done = 0;
const results = [];
const start = process.hrtime.bigint();
while (pool.queueSize === 0) {
results.push(scheduleTasks());
}
async function scheduleTasks () {
while ((process.hrtime.bigint() - start) / 1_000_000n < duration) {
await pool.run({ a: 4, b: 6 });
done++;
}
}
await Promise.all(results);
return done / duration * 1e3;
}
simpleBenchmark().then((opsPerSecond) => {
console.log(`opsPerSecond: ${opsPerSecond} (with FixedQueue as taskQueue)`);
});

29
node_modules/piscina/benchmark/simple-benchmark.js generated vendored Normal file
View File

@@ -0,0 +1,29 @@
'use strict';
const { Piscina } = require('..');
const { resolve } = require('path');
async function simpleBenchmark ({ duration = 10000 } = {}) {
const pool = new Piscina({ filename: resolve(__dirname, 'fixtures/add.js') });
let done = 0;
const results = [];
const start = process.hrtime.bigint();
while (pool.queueSize === 0) {
results.push(scheduleTasks());
}
async function scheduleTasks () {
while ((process.hrtime.bigint() - start) / 1_000_000n < duration) {
await pool.run({ a: 4, b: 6 });
done++;
}
}
await Promise.all(results);
return done / duration * 1e3;
}
simpleBenchmark().then((opsPerSecond) => {
console.log(`opsPerSecond: ${opsPerSecond} (with default taskQueue)`);
});