Skip to content

Commit

Permalink
chore: add native benchmarks in d
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jul 11, 2021
1 parent e419f7e commit f92e148
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,11 @@ dist
.parcel-cache
.dub
trace.*
*.exe
*.lib
*.a
*.dll
*.o
*.obj

test/fixtures/**/*-minified.json
17 changes: 17 additions & 0 deletions benchmark/benchmark.d
Original file line number Diff line number Diff line change
@@ -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);
}
7 changes: 7 additions & 0 deletions dub.sdl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "npm run build.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.*"
Expand Down
3 changes: 2 additions & 1 deletion src/native/lib.d
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ string minifyString(in string jsonString, in bool hasComment = false) @trusted
{
leftContextSubstr = leftContextSubstr.replaceAll(spaceOrBreakRegex, "");
}
if (!noLeftContext) {
if (!noLeftContext)
{
result ~= leftContextSubstr;
}

Expand Down

0 comments on commit f92e148

Please sign in to comment.