diff --git a/.gitignore b/.gitignore index 681ac3c..8e39793 100644 --- a/.gitignore +++ b/.gitignore @@ -14,5 +14,11 @@ dist .parcel-cache .dub trace.* +*.exe +*.lib +*.a +*.dll +*.o +*.obj test/fixtures/**/*-minified.json diff --git a/benchmark/benchmark.d b/benchmark/benchmark.d new file mode 100644 index 0000000..e57fd27 --- /dev/null +++ b/benchmark/benchmark.d @@ -0,0 +1,17 @@ +module minijson.benchmark; + +import minijson.lib: minifyFiles; + +import std.datetime.stopwatch: benchmark; +import std: dirEntries, array, SpanMode, writeln, map; + +void main() { + const string[] files = dirEntries("./test/fixtures/standard", SpanMode.shallow).map!(entry => entry.name).array(); + + void minifyFilesCaller() { + minifyFiles(files); + } + auto result = benchmark!(minifyFilesCaller)(1); + + writeln(result); +} diff --git a/dub.sdl b/dub.sdl index 3d45f72..6e3d796 100644 --- a/dub.sdl +++ b/dub.sdl @@ -21,6 +21,13 @@ configuration "library" { targetName "minijson" } +configuration "benchmark" { + targetType "executable" + targetName "minijson-benchmark" + mainSourceFile "./benchmark/benchmark.d" + excludedSourceFiles "src/native/cli.d" "src/native/libc.d" +} + # -------- Build Options and configurations -------- // enables all disp except =nosharedaccess diff --git a/package.json b/package.json index ab2d6c6..4b0318e 100644 --- a/package.json +++ b/package.json @@ -19,16 +19,17 @@ "test.lint": "eslint .", "test": "jasmine ./test/index-test.mjs", "clean": "shx rm -rf dist", - "build.native": "dub build --config=executable", - "build.native.release": "pnpm build.native -- --build release-nobounds --compiler=ldc2", - "build.native.profile": "pnpm build.native -- --build profile --compiler=ldc2 && node ./src/node/build.js && npm run build.node.js", + "build": "dub build --config=executable", + "build.release": "pnpm build.native -- --build release-nobounds --compiler=ldc2", + "build.profile": "pnpm build.native -- --build profile --compiler=ldc2 && node ./src/node/build.js && npm run build.node.js", + "build.benchmark": "dub build --config=benchmark --build release-nobounds --compiler=ldc2", "start.profile": "shx rm -rf ./trace.* && npm run start.benchmark && profdump.exe --dot trace.log trace.dot && dot -Tsvg trace.dot -o trace.svg && ./trace.svg", "build.node": "npm run build.native.release && node ./src/node/build.js && npm run build.node.js", "build.node.js": "tsc -p ./src/node/tsconfig.json", "build.wasm": "ldc2 ./src/wasm/wasm.d ./src/native/lib.d --od ./dist --O3 --mtriple=wasm32-unknown-unknown-wasm", "build.browser": "npm run build.wasm && parcel build --target browser ./src/browser/index.html", "start.browser": "servor ./dist/ --browse --reload", - "start.benchmark": "node ./benchmark/native-benchmark.mjs", + "start.benchmark.node": "node ./benchmark/native-benchmark.mjs", "start.node": "node ./dist/node/cli.js", "zip": "zip -9 -j ./dist/minijson-windows-x64.zip ./dist/win32-x64/minijson.exe && zip -9 -j ./dist/minijson-macos-x64.zip ./dist/darwin-x64/minijson && zip -9 -j ./dist/minijson-linux-x64.zip ./dist/linux-x64/minijson", "prepublishOnly": "shx rm -rf ./dist/tsconfig.tsbuildinfo ./dist/build.*" diff --git a/src/native/lib.d b/src/native/lib.d index fdee184..00611a4 100644 --- a/src/native/lib.d +++ b/src/native/lib.d @@ -51,7 +51,8 @@ string minifyString(in string jsonString, in bool hasComment = false) @trusted { leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, ""); } - if (!noLeftContext) { + if (!noLeftContext) + { result ~= leftContextSubstr; }