|
| 1 | +import findRoot from "find-root"; |
| 2 | +import fs from "fs"; |
| 3 | +import { pack, unpack } from "msgpackr"; |
| 4 | +import { LargeRoot } from "../spec/fixtures/LargeRoot"; |
| 5 | +import { TestClassModel } from "../spec/fixtures/TestClassModel"; |
| 6 | +import { BigTestModelSnapshot } from "../spec/fixtures/TestModel"; |
| 7 | +import { NameExample } from "../spec/fixtures/NameExample"; |
| 8 | +import { enableMsgpackrIntegration } from "../src/msgpackr-instantiator"; |
| 9 | +import { benchmarker } from "./benchmark"; |
| 10 | + |
| 11 | +const largeRootSnapshot = JSON.parse(fs.readFileSync(findRoot(__dirname) + "/spec/fixtures/large-root-snapshot.json", "utf8")); |
| 12 | +const largeRootMsgpack = pack(largeRootSnapshot); |
| 13 | + |
| 14 | +const bigTestModelMsgpack = pack(BigTestModelSnapshot); |
| 15 | +const smallTestSnapshot = { key: "test", name: "test" }; |
| 16 | +const smallTestMsgpack = pack(smallTestSnapshot); |
| 17 | + |
| 18 | +const LargeRootWithMsgpackr = enableMsgpackrIntegration(LargeRoot); |
| 19 | +const TestClassModelWithMsgpackr = enableMsgpackrIntegration(TestClassModel); |
| 20 | +const NameExampleWithMsgpackr = enableMsgpackrIntegration(NameExample); |
| 21 | + |
| 22 | +export default benchmarker(async (suite) => { |
| 23 | + suite |
| 24 | + .add("baseline: large root msgpack.unpack + createReadOnly", function () { |
| 25 | + const unpacked = unpack(largeRootMsgpack); |
| 26 | + LargeRoot.createReadOnly(unpacked); |
| 27 | + }) |
| 28 | + .add("fused: large root createReadOnlyFromMsgpack", function () { |
| 29 | + LargeRootWithMsgpackr.createReadOnlyFromMsgpack(largeRootMsgpack); |
| 30 | + }) |
| 31 | + .add("baseline: diverse model msgpack.unpack + createReadOnly", function () { |
| 32 | + const unpacked = unpack(bigTestModelMsgpack); |
| 33 | + TestClassModel.createReadOnly(unpacked); |
| 34 | + }) |
| 35 | + .add("fused: diverse model createReadOnlyFromMsgpack", function () { |
| 36 | + TestClassModelWithMsgpackr.createReadOnlyFromMsgpack(bigTestModelMsgpack); |
| 37 | + }) |
| 38 | + .add("baseline: small model msgpack.unpack + createReadOnly", function () { |
| 39 | + const unpacked = unpack(smallTestMsgpack); |
| 40 | + NameExample.createReadOnly(unpacked); |
| 41 | + }) |
| 42 | + .add("fused: small model createReadOnlyFromMsgpack", function () { |
| 43 | + NameExampleWithMsgpackr.createReadOnlyFromMsgpack(smallTestMsgpack); |
| 44 | + }); |
| 45 | + |
| 46 | + return suite; |
| 47 | +}); |
0 commit comments