| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -10,6 +10,7 @@ fs.writeFileSync(tmpfile, 'this-is-for-a-benchmark', 'utf8'); | |||
| 10 | 10 | ||
| 11 | 11 | const bench = common.createBenchmark(main, { | |
| 12 | 12 | type: ['existing', 'non-existing', 'non-flat-existing'], | |
| 13 | + method: ['access', 'accessSync'], | ||
| 13 | 14 | n: [1e5], | |
| 14 | 15 | }); | |
| 15 | 16 | ||
@@ -23,7 +24,17 @@ function runBench(n, path) { | |||
| 23 | 24 | } | |
| 24 | 25 | } | |
| 25 | 26 | ||
| 26 | - function main({ n, type }) { | ||
| 27 | + function runAsyncBench(n, path) { | ||
| 28 | + (function r(cntr, path) { | ||
| 29 | + if (cntr-- <= 0) | ||
| 30 | + return bench.end(n); | ||
| 31 | + fs.access(path, () => { | ||
| 32 | + r(cntr, path); | ||
| 33 | + }); | ||
| 34 | + })(n, path); | ||
| 35 | + } | ||
| 36 | + | ||
| 37 | + function main({ n, type, method }) { | ||
| 27 | 38 | let path; | |
| 28 | 39 | ||
| 29 | 40 | switch (type) { | |
@@ -39,10 +50,19 @@ function main({ n, type }) { | |||
| 39 | 50 | default: | |
| 40 | 51 | new Error('Invalid type'); | |
| 41 | 52 | } | |
| 42 | - // warmup | ||
| 43 | - runBench(n, path); | ||
| 44 | 53 | ||
| 45 | - bench.start(); | ||
| 46 | - runBench(n, path); | ||
| 47 | - bench.end(n); | ||
| 54 | + if (method === 'access') { | ||
| 55 | + // Warmup the filesystem - it doesn't need to use the async method | ||
| 56 | + runBench(n, path); | ||
| 57 | + | ||
| 58 | + bench.start(); | ||
| 59 | + runAsyncBench(n, path); | ||
| 60 | + } else { | ||
| 61 | + // warmup | ||
| 62 | + runBench(n, path); | ||
| 63 | + | ||
| 64 | + bench.start(); | ||
| 65 | + runBench(n, path); | ||
| 66 | + bench.end(n); | ||
| 67 | + } | ||
| 48 | 68 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments