Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions JetStreamDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,17 @@ let BENCHMARKS = [
exposeBrowserTest: true,
tags: ["Default", "RexBench"],
}),
new DefaultBenchmark({
name: "validatorjs",
files: [
// Use the unminified version for easier local profiling.
// "./validatorjs/dist/bundle.es6.js",
"./validatorjs/dist/bundle.es6.min.js",
"./validatorjs/benchmark.js",
],
allowUtf16: true,
tags: ["Default", "regexp"],
}),
// Simple
new DefaultBenchmark({
name: "hash-map",
Expand Down
24 changes: 24 additions & 0 deletions validatorjs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# validator.js test for JetStream

Measures the performance of the validator.js library by running the core test suite.

## Build Instructions

```bash
# install required node packages.
npm ci
# build the workload, output is ./dist
npm run build
```

## Workloads

The workload is a modified copy of the validator.js [test suite](https://github.com/validatorjs/validator.js/tree/master/test).
Several files are combined together and contents copied to the `runTest` method.

Modifications to the original:
- Any tests that depend on node internal values have been removed.
- Date constructions with an arg-array differs between browser and thus they
are replaced by direct arguments.
- Direct calls to validater.xzy() are replaced with validatorjs.xzy() to not
conflict with the default argument to the mock test() method.
6 changes: 6 additions & 0 deletions validatorjs/benchmark-node.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { runTest } from "./src/test.mjs";

const then = performance.now();
runTest();
const duration = performance.now() - then;
console.log(`Duration: ${duration.toFixed(2)}ms`);
41 changes: 41 additions & 0 deletions validatorjs/benchmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright (C) 2025 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

const EXPECTED_ASSERTION_COUNT = 10114;

class Benchmark {
assertionCount = 0;

runIteration() {
this.assertionCount = ValidatorJSBenchmark.runTest();
}

validate() {
console.assert(
this.assertionCount === EXPECTED_ASSERTION_COUNT,
`Expected ${EXPECTED_ASSERTION_COUNT} assertions, but got ${this.assertionCount}`
);
}
}
Loading
Loading