Skip to content

Commit be553cc

Browse files
authored
Add a benchmark to the tests (#631)
1 parent 2930f6b commit be553cc

File tree

5 files changed

+39
-0
lines changed

5 files changed

+39
-0
lines changed

.github/workflows/js.yml

+4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ jobs:
5252
working-directory: client
5353
run: pnpm run test
5454

55+
- name: Run benchmarks
56+
working-directory: client
57+
run: pnpm run bench
58+
5559
detect_docs:
5660
runs-on: ubuntu-latest
5761
if: github.ref == 'refs/heads/main'

client/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"build": "turbo run build --cache-dir=.turbo",
1616
"dev": "turbo run dev --parallel",
1717
"test": "turbo run test:ci",
18+
"bench": "turbo run bench:ci",
1819
"format": "prettier --write --config ./.prettierrc \"**/*.{ts,tsx,js,jsx,json,md}\"",
1920
"publish-packages": "turbo run publish-package --filter=\"./packages/*\"",
2021
"build-packages": "turbo run build --filter=\"./packages/*\" --cache-dir=.turbo",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { bench } from "vitest";
2+
3+
import zenecaAttrs from "./data/zeneca/attrs.json";
4+
import zenecaTriples from "./data/zeneca/triples.json";
5+
import { createStore } from "../../src/store";
6+
import query from "../../src/instaql";
7+
8+
const zenecaIdToAttr = zenecaAttrs.reduce((res, x) => {
9+
res[x.id] = x;
10+
return res;
11+
}, {});
12+
13+
const store = createStore(zenecaIdToAttr, zenecaTriples);
14+
15+
bench("big query", () => {
16+
query(
17+
{ store },
18+
{
19+
users: {
20+
bookshelves: {
21+
books: {},
22+
users: {
23+
bookshelves: {},
24+
},
25+
},
26+
},
27+
},
28+
);
29+
});

client/packages/core/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
"unpkg": "standalone/index.umd.js",
99
"scripts": {
1010
"test": "vitest",
11+
"bench": "vitest bench",
1112
"test:ci": "vitest run",
13+
"bench:ci": "vitest bench --run",
1214
"check": "tsc --noEmit",
1315
"build": "rm -rf dist; npm run build:main && npm run build:module && npm run build:standalone",
1416
"dev:main": "tsc -p tsconfig.json -w --skipLibCheck",

client/turbo.json

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
"test:ci": {
1717
"outputs": []
1818
},
19+
"bench:ci": {
20+
"outputs": []
21+
},
1922
"dev": {
2023
"cache": false,
2124
"persistent": true

0 commit comments

Comments
 (0)