From d64c24f300cf9edacd3c8f090fe54744d6382c66 Mon Sep 17 00:00:00 2001 From: mrmlnc Date: Mon, 10 Jun 2019 09:12:31 +0300 Subject: [PATCH] build(benchmark): add suite for stream API --- package.json | 5 +++- .../suites/stream/fast-glob-current.ts | 26 +++++++++++++++++++ .../suites/stream/fast-glob-previous.ts | 26 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/benchmark/suites/stream/fast-glob-current.ts create mode 100644 src/benchmark/suites/stream/fast-glob-previous.ts diff --git a/package.json b/package.json index c7e66dec..3e7b3b67 100644 --- a/package.json +++ b/package.json @@ -65,11 +65,14 @@ "smoke": "mocha \"out/**/*.smoke.js\" -s 0", "build": "npm run clean && npm run compile && npm run lint && npm test", "watch": "npm run clean && npm run compile -- --sourceMap --watch", - "bench": "npm run bench-async && npm run bench-sync", + "bench": "npm run bench-async && npm run bench-stream && npm run bench-sync", "bench-async": "npm run bench-async-flatten && npm run bench-async-deep", + "bench-stream": "npm run bench-stream-flatten && npm run bench-stream-deep", "bench-sync": "npm run bench-sync-flatten && npm run bench-sync-deep", "bench-async-flatten": "node ./out/benchmark --type async --pattern \"*\"", "bench-async-deep": "node ./out/benchmark --type async --pattern \"**\"", + "bench-stream-flatten": "node ./out/benchmark --type stream --pattern \"*\"", + "bench-stream-deep": "node ./out/benchmark --type stream --pattern \"**\"", "bench-sync-flatten": "node ./out/benchmark --type sync --pattern \"*\"", "bench-sync-deep": "node ./out/benchmark --type sync --pattern \"**\"" } diff --git a/src/benchmark/suites/stream/fast-glob-current.ts b/src/benchmark/suites/stream/fast-glob-current.ts new file mode 100644 index 00000000..46ff9744 --- /dev/null +++ b/src/benchmark/suites/stream/fast-glob-current.ts @@ -0,0 +1,26 @@ +import * as path from 'path'; + +import * as glob from '../../../index'; +import Settings from '../../../settings'; +import * as utils from '../../utils'; + +const settings = new Settings({ + cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), + unique: false +}); + +const entries: Set = new Set(); + +const timeStart = utils.timeStart(); + +const stream = glob.stream(process.env.BENCHMARK_PATTERN as string, settings); + +stream.once('error', () => process.exit(0)); +stream.on('data', (entry) => entries.add(entry)); +stream.once('end', () => { + const memory = utils.getMemory(); + const time = utils.timeEnd(timeStart); + const measures = utils.getMeasures(Array.from(entries).length, time, memory); + + console.info(measures); +}); diff --git a/src/benchmark/suites/stream/fast-glob-previous.ts b/src/benchmark/suites/stream/fast-glob-previous.ts new file mode 100644 index 00000000..4471fed3 --- /dev/null +++ b/src/benchmark/suites/stream/fast-glob-previous.ts @@ -0,0 +1,26 @@ +import * as path from 'path'; + +import fg = require('fast-glob'); + +import * as utils from '../../utils'; + +const options: fg.Options = { + cwd: path.join(process.cwd(), process.env.BENCHMARK_BASE_DIR as string), + unique: false +}; + +const entries: Set = new Set(); + +const timeStart = utils.timeStart(); + +const stream = fg.stream(process.env.BENCHMARK_PATTERN as string, options); + +stream.once('error', () => process.exit(0)); +stream.on('data', (entry) => entries.add(entry)); +stream.once('end', () => { + const memory = utils.getMemory(); + const time = utils.timeEnd(timeStart); + const measures = utils.getMeasures(Array.from(entries).length, time, memory); + + console.info(measures); +});