Skip to content

Commit f92e148

Browse files
committed
chore: add native benchmarks in d
1 parent e419f7e commit f92e148

File tree

5 files changed

+38
-6
lines changed

5 files changed

+38
-6
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,11 @@ dist
1414
.parcel-cache
1515
.dub
1616
trace.*
17+
*.exe
18+
*.lib
19+
*.a
20+
*.dll
21+
*.o
22+
*.obj
1723

1824
test/fixtures/**/*-minified.json

benchmark/benchmark.d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module minijson.benchmark;
2+
3+
import minijson.lib: minifyFiles;
4+
5+
import std.datetime.stopwatch: benchmark;
6+
import std: dirEntries, array, SpanMode, writeln, map;
7+
8+
void main() {
9+
const string[] files = dirEntries("./test/fixtures/standard", SpanMode.shallow).map!(entry => entry.name).array();
10+
11+
void minifyFilesCaller() {
12+
minifyFiles(files);
13+
}
14+
auto result = benchmark!(minifyFilesCaller)(1);
15+
16+
writeln(result);
17+
}

dub.sdl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ configuration "library" {
2121
targetName "minijson"
2222
}
2323

24+
configuration "benchmark" {
25+
targetType "executable"
26+
targetName "minijson-benchmark"
27+
mainSourceFile "./benchmark/benchmark.d"
28+
excludedSourceFiles "src/native/cli.d" "src/native/libc.d"
29+
}
30+
2431
# -------- Build Options and configurations --------
2532

2633
// enables all disp except =nosharedaccess

package.json

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,17 @@
1919
"test.lint": "eslint .",
2020
"test": "jasmine ./test/index-test.mjs",
2121
"clean": "shx rm -rf dist",
22-
"build.native": "dub build --config=executable",
23-
"build.native.release": "pnpm build.native -- --build release-nobounds --compiler=ldc2",
24-
"build.native.profile": "pnpm build.native -- --build profile --compiler=ldc2 && node ./src/node/build.js && npm run build.node.js",
22+
"build": "dub build --config=executable",
23+
"build.release": "pnpm build.native -- --build release-nobounds --compiler=ldc2",
24+
"build.profile": "pnpm build.native -- --build profile --compiler=ldc2 && node ./src/node/build.js && npm run build.node.js",
25+
"build.benchmark": "dub build --config=benchmark --build release-nobounds --compiler=ldc2",
2526
"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",
26-
"build.node": "npm run build.native.release && node ./src/node/build.js && npm run build.node.js",
27+
"build.node": "npm run build.release && node ./src/node/build.js && npm run build.node.js",
2728
"build.node.js": "tsc -p ./src/node/tsconfig.json",
2829
"build.wasm": "ldc2 ./src/wasm/wasm.d ./src/native/lib.d --od ./dist --O3 --mtriple=wasm32-unknown-unknown-wasm",
2930
"build.browser": "npm run build.wasm && parcel build --target browser ./src/browser/index.html",
3031
"start.browser": "servor ./dist/ --browse --reload",
31-
"start.benchmark": "node ./benchmark/native-benchmark.mjs",
32+
"start.benchmark.node": "node ./benchmark/native-benchmark.mjs",
3233
"start.node": "node ./dist/node/cli.js",
3334
"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",
3435
"prepublishOnly": "shx rm -rf ./dist/tsconfig.tsbuildinfo ./dist/build.*"

src/native/lib.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ string minifyString(in string jsonString, in bool hasComment = false) @trusted
5151
{
5252
leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, "");
5353
}
54-
if (!noLeftContext) {
54+
if (!noLeftContext)
55+
{
5556
result ~= leftContextSubstr;
5657
}
5758

0 commit comments

Comments
 (0)