diff --git a/benchmark/module/module-loader.js b/benchmark/module/module-loader.js index d40e36dc3e3..cca5fc2c229 100644 --- a/benchmark/module/module-loader.js +++ b/benchmark/module/module-loader.js @@ -3,8 +3,8 @@ const fs = require('fs'); const path = require('path'); const common = require('../common.js'); -const tmpDirectory = path.join(__dirname, '..', 'tmp'); -const benchmarkDirectory = path.join(tmpDirectory, 'nodejs-benchmark-module'); +const { refreshTmpDir, tmpDir } = require('../../test/common'); +const benchmarkDirectory = path.join(tmpDir, 'nodejs-benchmark-module'); const bench = common.createBenchmark(main, { thousands: [50], @@ -15,8 +15,7 @@ const bench = common.createBenchmark(main, { function main(conf) { const n = +conf.thousands * 1e3; - rmrf(tmpDirectory); - try { fs.mkdirSync(tmpDirectory); } catch (e) {} + refreshTmpDir(); try { fs.mkdirSync(benchmarkDirectory); } catch (e) {} for (var i = 0; i <= n; i++) { @@ -36,7 +35,7 @@ function main(conf) { else measureDir(n, conf.useCache === 'true'); - rmrf(tmpDirectory); + refreshTmpDir(); } function measureFull(n, useCache) { @@ -66,21 +65,3 @@ function measureDir(n, useCache) { } bench.end(n / 1e3); } - -function rmrf(location) { - try { - const things = fs.readdirSync(location); - things.forEach(function(thing) { - var cur = path.join(location, thing), - isDirectory = fs.statSync(cur).isDirectory(); - if (isDirectory) { - rmrf(cur); - return; - } - fs.unlinkSync(cur); - }); - fs.rmdirSync(location); - } catch (err) { - // Ignore error - } -}