-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
188 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { Suite } = require('../../lib'); | ||
|
||
const suite = new Suite({ | ||
useWorkers: true, | ||
}); | ||
|
||
suite | ||
.add('Using import without node: prefix', function () { | ||
return import('fs'); | ||
}) | ||
.add('Using import with node: prefix', function () { | ||
return import('node:fs'); | ||
}) | ||
.run(); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
const { parentPort } = require('worker_threads'); | ||
const { runBenchmark } = require('./lifecycle'); | ||
|
||
// Deserialize the benchmark function | ||
function deserializeBenchmark(benchmark) { | ||
benchmark.fn = new Function(benchmark.fn); | ||
} | ||
|
||
parentPort.on('message', async ({ benchmark, initialIterations, repeatSuite }) => { | ||
deserializeBenchmark(benchmark); | ||
const result = await runBenchmark(benchmark, initialIterations, repeatSuite); | ||
parentPort.postMessage(result); | ||
}); |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const workerThreads = require('node:worker_threads'); | ||
const { describe, it, before, after, mock } = require('node:test'); | ||
const assert = require('node:assert'); | ||
|
||
function noop() {} | ||
|
||
describe('Using worker_threads', () => { | ||
before(async () => { | ||
mock.method(workerThreads, 'Worker'); | ||
|
||
const { Suite } = require('../lib/index'); | ||
|
||
const bench = new Suite({ | ||
reporter: noop, | ||
useWorkers: true | ||
}); | ||
|
||
bench | ||
.add('Import with node: prefix', () => { | ||
return import('node:fs'); | ||
}) | ||
.add('Import without node: prefix', () => { | ||
return import('fs'); | ||
}); | ||
await bench.run(); | ||
}); | ||
|
||
after(() => { | ||
mock.restoreAll(); | ||
}) | ||
|
||
it('should create a new Worker 2 times', () => { | ||
assert.strictEqual(workerThreads.Worker.mock.calls.length, 2); | ||
}); | ||
}); |