forked from oven-sh/bun
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement `fs.readdir(path, {recursive: true})` and `fs.readdirSync(path, {recursive: true})` * Update node_fs.zig * FIx memory leak in error code * Add fail test * Update readdir.mjs * Update bun.zig * Update readdir.mjs --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
857 additions
and
58 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 |
---|---|---|
@@ -1,13 +1,50 @@ | ||
import { readdirSync } from "fs"; | ||
import { readdirSync, readdir as readdirCb } from "fs"; | ||
import { readdir } from "fs/promises"; | ||
import { bench, run } from "./runner.mjs"; | ||
import { argv } from "process"; | ||
import { fileURLToPath } from "url"; | ||
import { relative, resolve } from "path"; | ||
import { createHash } from "crypto"; | ||
|
||
const dir = argv.length > 2 ? argv[2] : "/tmp"; | ||
let dir = resolve(argv.length > 2 ? argv[2] : fileURLToPath(new URL("../../node_modules", import.meta.url))); | ||
if (dir.includes(process.cwd())) { | ||
dir = relative(process.cwd(), dir); | ||
} | ||
|
||
const count = readdirSync(dir).length; | ||
bench(`readdir("${dir}")`, () => { | ||
readdirSync(dir, { withFileTypes: true }); | ||
const result = await readdir(dir, { recursive: true }); | ||
const count = result.length; | ||
const syncCount = readdirSync(dir, { recursive: true }).length; | ||
|
||
const hash = createHash("sha256").update(result.sort().join("\n")).digest("hex"); | ||
|
||
bench(`await readdir("${dir}", {recursive: true})`, async () => { | ||
await readdir(dir, { recursive: true }); | ||
}); | ||
|
||
bench(`await readdir("${dir}", {recursive: true}) x 10`, async () => { | ||
const promises = [ | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
readdir(dir, { recursive: true }), | ||
]; | ||
await Promise.all(promises); | ||
}); | ||
|
||
bench(`await readdir("${dir}", {recursive: false})`, async () => { | ||
await readdir(dir, { recursive: false }); | ||
}); | ||
|
||
await run(); | ||
console.log("\n\nFor", count, "files/dirs in", dir); | ||
console.log("\n", count, "files/dirs in", dir, "\n", "SHA256:", hash, "\n"); | ||
|
||
if (count !== syncCount) { | ||
throw new Error(`Mismatched file counts: ${count} async !== ${syncCount} sync`); | ||
} |
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
Oops, something went wrong.