Skip to content

Commit 85e9bd5

Browse files
committed
Implement basic benchmarks
Pre 2.0.0 instance methods vs >2.0.0 static methods
1 parent 14423da commit 85e9bd5

1 file changed

Lines changed: 44 additions & 0 deletions

File tree

benchmark.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
"use strict";
2+
const inv = require("install-npm-version");
3+
const benchmarkVersion = "1.0.1";
4+
const benchmarkLib = `postcode@${benchmarkVersion}`;
5+
6+
const message = `
7+
Benchmarking master against ${benchmarkLib}
8+
9+
`;
10+
11+
inv
12+
.Install(benchmarkLib, { Verbosity: "debug" })
13+
.then(() => runBenchmarks())
14+
.catch(error => {
15+
console.log(error);
16+
process.exit(1);
17+
});
18+
19+
const runBenchmarks = () => {
20+
const { Suite } = require("benchmark");
21+
const suite = new Suite();
22+
23+
const Postcode = require("./dist/index");
24+
const PreviousPostcode = require(benchmarkLib);
25+
26+
const extractInputs = ({ tests }) => tests.map(({ base }) => base);
27+
28+
const validation = extractInputs(require("./test/data/validation.json"));
29+
suite
30+
.add(`(version: ${benchmarkVersion}) Postcode#valid`, () => {
31+
validation.forEach(postcode => {
32+
const result = new PreviousPostcode(postcode).valid();
33+
});
34+
})
35+
.add("(version: master) Postcode.isValid", () => {
36+
validation.forEach(postcode => {
37+
const result = Postcode.isValid(postcode);
38+
});
39+
})
40+
.on("cycle", event => {
41+
console.log(String(event.target));
42+
})
43+
.run({});
44+
};

0 commit comments

Comments
 (0)