Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
squash: optimize benchmark
  • Loading branch information
LiviaMedeiros committed May 22, 2025
commit 531d6be411c8f79d247d3c6ecd2aa9ae718fb582
30 changes: 18 additions & 12 deletions benchmark/fs/bench-glob.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
'use strict';

const common = require('../common');
const fs = require('fs');
const {
glob,
globSync,
promises: { glob: globAsync },
} = require('fs');
const path = require('path');
const assert = require('node:assert');

Expand All @@ -20,28 +24,30 @@
async function main(config) {
const fullPath = path.resolve(benchmarkDirectory, config.dir);
const { pattern, recursive, mode } = config;
const options = { cwd: fullPath, recursive };
const callback = (resolve, reject) => {
glob(pattern, options, (err, matches) => {
if (err) {
reject(err)

Check failure on line 31 in benchmark/fs/bench-glob.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon
} else {
resolve(matches);
}
});
}

Check failure on line 36 in benchmark/fs/bench-glob.js

View workflow job for this annotation

GitHub Actions / lint-js-and-md

Missing semicolon

let noDead;
bench.start();

for (let i = 0; i < config.n; i++) {
switch (mode) {
case 'sync':
noDead = fs.globSync(pattern, { cwd: fullPath, recursive });
noDead = globSync(pattern, options);
break;
case 'promise':
noDead = await fs.promises.glob(pattern, { cwd: fullPath, recursive });
noDead = await globAsync(pattern, options);
break;
case 'callback':
noDead = await new Promise((resolve, reject) => {
fs.glob(pattern, { cwd: fullPath, recursive }, (err, matches) => {
if (err) {
reject(err);
} else {
resolve(matches);
}
});
});
noDead = await new Promise(callback);
break;
default:
throw new Error(`Unknown mode: ${mode}`);
Expand Down
Loading