-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Optimise PropertyFilter.fromString (#63)
* Optimise PropertyFilter.fromString * Codecov: ignore __benchmark__ * Add tests * Codecov: ignore __benchmark__ try #2 * Fix codecov & validate structure --------- Co-authored-by: Oskar Dahlin <oskar.dahlin@divid.se>
- Loading branch information
Showing
5 changed files
with
81 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
packages/property/src/__benchmarks__/property-filter-parse.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import * as Benchmark from "benchmark"; | ||
import { BaseUnits, UnitMap } from "uom"; | ||
import { PropertyFilter } from "../index"; | ||
|
||
const suite = new Benchmark.Suite(); | ||
|
||
const unitLookup: UnitMap.UnitLookup = (unitString) => (BaseUnits as UnitMap.UnitMap)[unitString]; | ||
|
||
const pf = PropertyFilter.fromString( | ||
"ccc=20&a=1,2,3~10&d=-50&(ccc=20|a=1,2)&d=5|z=50", | ||
unitLookup | ||
// "a=1" | ||
); | ||
if (!pf) { | ||
throw new Error("Could not create property filter."); | ||
} | ||
|
||
suite | ||
// add tests | ||
.add("PropertyFilter#fromString empty", () => { | ||
PropertyFilter.fromString("", unitLookup); | ||
}) | ||
.add("PropertyFilter#fromString whitespace", () => { | ||
PropertyFilter.fromString(" ", unitLookup); | ||
}) | ||
.add("PropertyFilter#fromString cache hit", () => { | ||
PropertyFilter.fromString("ccc=20&a=1,2,3~10&d=-50&(ccc=20|a=1,2)&d=5|z=50", unitLookup); | ||
}) | ||
.add("PropertyFilter#fromString cache miss", () => { | ||
const randomValue = Math.floor(Math.random() * 100000); | ||
PropertyFilter.fromString(`ccc=20&a=1,2,3~10&d=-50&(randomvalue=${randomValue}|a=1,2)&d=5|z=50`, unitLookup); | ||
}) | ||
.on("start", () => { | ||
console.log("Started benchmark"); | ||
}) | ||
// add listeners | ||
.on("cycle", (event: Event) => { | ||
console.log(String(event.target)); | ||
}) | ||
// run async | ||
.run({ async: true }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters