-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to tinybench and add a property access benchmark
- Loading branch information
Showing
10 changed files
with
274 additions
and
145 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,17 @@ | ||
import { Suite } from "benchmark"; | ||
import { Bench } from "tinybench"; | ||
import findRoot from "find-root"; | ||
import fs from "fs"; | ||
import { LargeRoot } from "../spec/fixtures/LargeRoot"; | ||
|
||
const snapshot = JSON.parse(fs.readFileSync(findRoot(__dirname) + "/spec/fixtures/large-root-snapshot.json", "utf8")); | ||
const suite = new Suite("instantiating a very large root"); | ||
void (async () => { | ||
const suite = new Bench(); | ||
|
||
suite | ||
.add("instantiating a large root", function () { | ||
suite.add("instantiating a large root", function () { | ||
LargeRoot.createReadOnly(snapshot); | ||
}) | ||
.on("start", function () { | ||
console.profile(); | ||
}) | ||
.on("cycle", function (event: any) { | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", function (this: Suite) { | ||
console.profileEnd(); | ||
}) | ||
.run({ async: true }); | ||
}); | ||
|
||
await suite.warmup(); | ||
await suite.run(); | ||
console.table(suite.table()); | ||
})(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,19 @@ | ||
import { Suite } from "benchmark"; | ||
import { Bench } from "tinybench"; | ||
import findRoot from "find-root"; | ||
import fs from "fs"; | ||
import { FruitAisle } from "../spec/fixtures/FruitAisle"; | ||
|
||
const root = findRoot(__dirname); | ||
const fruitBasket = JSON.parse(fs.readFileSync(root + "/spec/fixtures/fruit-aisle-snapshot.json", "utf8")); | ||
const suite = new Suite("instantiating model classes"); | ||
|
||
suite | ||
.add("instantiating a large union", function () { | ||
void (async () => { | ||
const suite = new Bench(); | ||
|
||
suite.add("instantiating a large union", function () { | ||
FruitAisle.createReadOnly(fruitBasket); | ||
}) | ||
.on("start", function () { | ||
console.profile(); | ||
}) | ||
.on("cycle", function (event: any) { | ||
console.log(String(event.target)); | ||
}) | ||
.on("complete", function (this: Suite) { | ||
console.profileEnd(); | ||
}) | ||
.run({ async: true }); | ||
}); | ||
|
||
await suite.warmup(); | ||
await suite.run(); | ||
console.table(suite.table()); | ||
})(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { Bench } from "tinybench"; | ||
import findRoot from "find-root"; | ||
import fs from "fs"; | ||
import { FruitAisle } from "../spec/fixtures/FruitAisle"; | ||
|
||
const root = findRoot(__dirname); | ||
const fruitBasket = JSON.parse(fs.readFileSync(root + "/spec/fixtures/fruit-aisle-snapshot.json", "utf8")); | ||
|
||
void (async () => { | ||
const suite = new Bench({ throws: true }); | ||
|
||
const shared = FruitAisle.createReadOnly(fruitBasket); | ||
|
||
const touchProperties = (instance: FruitAisle) => { | ||
instance.binCount; | ||
instance.null; | ||
instance.firstBinCount; | ||
instance.firstBinType; | ||
}; | ||
|
||
let instance: FruitAisle; | ||
|
||
suite | ||
.add( | ||
"accessing unmemoized null property of a class model", | ||
function () { | ||
instance.null; | ||
}, | ||
{ | ||
beforeEach() { | ||
instance = FruitAisle.createReadOnly(fruitBasket); | ||
}, | ||
} | ||
) | ||
.add("accessing memoized null property of a class model", function () { | ||
shared.null; | ||
}) | ||
.add( | ||
"accessing unmemoized getter properties of a class model", | ||
function () { | ||
touchProperties(instance); | ||
}, | ||
{ | ||
beforeEach() { | ||
instance = FruitAisle.createReadOnly(fruitBasket); | ||
}, | ||
} | ||
) | ||
.add("accessing memoized getter properties of a class model", function () { | ||
touchProperties(shared); | ||
}); | ||
|
||
await suite.warmup(); | ||
await suite.run(); | ||
console.table(suite.table()); | ||
})(); |
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
Oops, something went wrong.