@wxn0brp/db-benchmark 0.0.0-stage → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -2
- package/package.json +34 -5
- package/src/custom/dir-index.ts +7 -0
- package/src/custom/sqlite.ts +41 -0
- package/src/db.ts +13 -0
- package/src/generate-static.ts +35 -0
- package/src/generate.ts +50 -0
- package/src/index.ts +31 -0
- package/src/large.ts +107 -0
- package/src/local/args.ts +63 -0
- package/src/local/cloud.ts +143 -0
- package/src/local/compare.ts +159 -0
- package/src/local/display.ts +84 -0
- package/src/local/index.ts +113 -0
- package/src/page/cache.ts +33 -0
- package/src/page/compare.ts +435 -0
- package/src/page/index.ts +113 -0
- package/src/page/local.ts +188 -0
- package/src/page/summary.ts +164 -0
- package/src/page/tables.ts +212 -0
- package/src/page/types.ts +33 -0
- package/src/page/utils.ts +58 -0
- package/src/page/var.ts +31 -0
- package/src/run.ts +25 -0
- package/src/small.ts +95 -0
- package/src/utils.ts +71 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 wxn0brP
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
-
#
|
|
1
|
+
# ValtheraDB Benchmark
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Benchmark suite for [ValtheraDB](https://github.com/wxn0brP/ValtheraDB) -
|
|
4
|
+
measures CRUD operation performance across adapters, runtimes, and platforms.
|
|
5
|
+
|
|
6
|
+
See [Page](https://wxn0brp.github.io/ValtheraDB-benchmark) for details and visualizations.
|
|
7
|
+
|
|
8
|
+
## License
|
|
9
|
+
|
|
10
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "@wxn0brp/db-benchmark",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"main": "dist/index.js",
|
|
5
|
+
"description": "",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/wxn0brP/ValtheraDB-benchmark.git"
|
|
9
|
+
},
|
|
10
|
+
"homepage": "https://github.com/wxn0brP/ValtheraDB-benchmark",
|
|
11
|
+
"author": "wxn0brP",
|
|
12
|
+
"license": "MIT",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"bin": {
|
|
15
|
+
"valthera-bench": "src/local/index.ts"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"src",
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsc && tsc-alias",
|
|
23
|
+
"build:page": "bun build src/page/index.ts --outdir public --sourcemap --minify"
|
|
24
|
+
},
|
|
25
|
+
"devDependencies": {
|
|
26
|
+
"@types/bun": "*",
|
|
27
|
+
"@wxn0brp/biome": "*",
|
|
28
|
+
"tsc-alias": "^1",
|
|
29
|
+
"typescript": "^7"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@wxn0brp/db-core": "^0.12.2",
|
|
33
|
+
"@wxn0brp/db-resolver": "^0.120.0"
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
export async function init(action: any) {
|
|
2
|
+
const schemas = [
|
|
3
|
+
`
|
|
4
|
+
CREATE TABLE IF NOT EXISTS users (
|
|
5
|
+
_id TEXT PRIMARY KEY,
|
|
6
|
+
name TEXT,
|
|
7
|
+
age INTEGER,
|
|
8
|
+
email TEXT,
|
|
9
|
+
isActive INTEGER,
|
|
10
|
+
createdAt INTEGER
|
|
11
|
+
)`,
|
|
12
|
+
`
|
|
13
|
+
CREATE TABLE IF NOT EXISTS posts (
|
|
14
|
+
_id TEXT PRIMARY KEY,
|
|
15
|
+
title TEXT,
|
|
16
|
+
author TEXT,
|
|
17
|
+
views INTEGER,
|
|
18
|
+
createdAt INTEGER
|
|
19
|
+
)`,
|
|
20
|
+
];
|
|
21
|
+
|
|
22
|
+
for (const sql of schemas) {
|
|
23
|
+
const stmt = await action._prepare(sql);
|
|
24
|
+
await stmt.run();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
await action
|
|
28
|
+
._prepare(
|
|
29
|
+
"CREATE INDEX IF NOT EXISTS idx_users_isActive ON users(isActive)",
|
|
30
|
+
)
|
|
31
|
+
.then(s => s.run());
|
|
32
|
+
await action
|
|
33
|
+
._prepare("CREATE INDEX IF NOT EXISTS idx_users_age ON users(age)")
|
|
34
|
+
.then(s => s.run());
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function onAfterAdd(action: any) {
|
|
38
|
+
await action
|
|
39
|
+
._prepare("CREATE INDEX IF NOT EXISTS idx_posts_views ON posts(views)")
|
|
40
|
+
.then(s => s.run());
|
|
41
|
+
}
|
package/src/db.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ValtheraClass } from "@wxn0brp/db-core";
|
|
2
|
+
import { createAdapter } from "@wxn0brp/db-resolver";
|
|
3
|
+
|
|
4
|
+
process.env.VALTHERA_MASTER_OPTS = (
|
|
5
|
+
process.env.VALTHERA_MASTER_OPTS || "[]"
|
|
6
|
+
).replace("$$", Date.now().toString());
|
|
7
|
+
|
|
8
|
+
const adapter = await createAdapter({
|
|
9
|
+
name: "master",
|
|
10
|
+
});
|
|
11
|
+
export const db = new ValtheraClass({
|
|
12
|
+
adapter,
|
|
13
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { mkdirSync, writeFileSync } from "fs";
|
|
2
|
+
import { chromium } from "playwright";
|
|
3
|
+
|
|
4
|
+
mkdirSync("result", {
|
|
5
|
+
recursive: true,
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
const browser = await chromium.launch();
|
|
9
|
+
const page = await browser.newPage({
|
|
10
|
+
viewport: {
|
|
11
|
+
width: 1280,
|
|
12
|
+
height: 900,
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
await page.goto(`http://wxn0brp.github.io/ValtheraDB-benchmark/`, {
|
|
17
|
+
waitUntil: "networkidle",
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
await page.waitForSelector("#loader", {
|
|
21
|
+
state: "hidden",
|
|
22
|
+
timeout: 120000,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
await page.waitForTimeout(2400);
|
|
26
|
+
|
|
27
|
+
await page.selectOption("#tables-adapter-select", "ALL");
|
|
28
|
+
await page.waitForTimeout(500);
|
|
29
|
+
|
|
30
|
+
const fullHtml = await page.content();
|
|
31
|
+
writeFileSync("result/static.html", fullHtml);
|
|
32
|
+
|
|
33
|
+
console.log("Finished");
|
|
34
|
+
|
|
35
|
+
await browser.close();
|
package/src/generate.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export interface UserData {
|
|
2
|
+
name: string;
|
|
3
|
+
age: number;
|
|
4
|
+
email: string;
|
|
5
|
+
isActive: boolean;
|
|
6
|
+
createdAt: number;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface PostData {
|
|
10
|
+
title: string;
|
|
11
|
+
author: string;
|
|
12
|
+
views: number;
|
|
13
|
+
createdAt: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function generateUsers(count: number): UserData[] {
|
|
17
|
+
const users: UserData[] = new Array(count);
|
|
18
|
+
const now = Date.now();
|
|
19
|
+
for (let i = 0; i < count; i++) {
|
|
20
|
+
users[i] = {
|
|
21
|
+
name: `User_${i}`,
|
|
22
|
+
age: 18 + (i % 50),
|
|
23
|
+
email: `user${i}@example.com`,
|
|
24
|
+
isActive: i % 3 !== 0,
|
|
25
|
+
createdAt: now + i,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return users;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function generatePosts(count: number): PostData[] {
|
|
32
|
+
const posts: PostData[] = new Array(count);
|
|
33
|
+
const now = Date.now();
|
|
34
|
+
const authors = [
|
|
35
|
+
"alice",
|
|
36
|
+
"bob",
|
|
37
|
+
"charlie",
|
|
38
|
+
"dave",
|
|
39
|
+
"eve",
|
|
40
|
+
];
|
|
41
|
+
for (let i = 0; i < count; i++) {
|
|
42
|
+
posts[i] = {
|
|
43
|
+
title: `Post_${i}`,
|
|
44
|
+
author: authors[i % authors.length],
|
|
45
|
+
views: i % 10000,
|
|
46
|
+
createdAt: now + i,
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
return posts;
|
|
50
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { db } from "./db";
|
|
2
|
+
import { benchmarkLarge } from "./large";
|
|
3
|
+
import { type BenchResult } from "./run";
|
|
4
|
+
import { benchmarkSmall } from "./small";
|
|
5
|
+
import { loadCustomSetup, writeResults } from "./utils";
|
|
6
|
+
|
|
7
|
+
const adapterName = process.env.VALTHERA_MASTER || "";
|
|
8
|
+
|
|
9
|
+
const [pkg] = adapterName.split(":");
|
|
10
|
+
const onAfterAdd = await loadCustomSetup(pkg, db.adapter);
|
|
11
|
+
|
|
12
|
+
const allResults: BenchResult[] = [];
|
|
13
|
+
|
|
14
|
+
console.log("small collection (users, 10k)");
|
|
15
|
+
const smallResults = await benchmarkSmall(db.c("users"));
|
|
16
|
+
allResults.push(...smallResults);
|
|
17
|
+
|
|
18
|
+
console.log("large collection (posts, 200k)");
|
|
19
|
+
const largeResults = await benchmarkLarge(db.c("posts"), onAfterAdd);
|
|
20
|
+
allResults.push(...largeResults);
|
|
21
|
+
|
|
22
|
+
writeResults("result.json", {
|
|
23
|
+
results: allResults,
|
|
24
|
+
adapter: process.env.VALTHERA_MASTER || "N/A",
|
|
25
|
+
coreVersion: db.version,
|
|
26
|
+
adapterVersion: db.adapter?.version || "N/A",
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
await db.close();
|
|
30
|
+
|
|
31
|
+
setTimeout(() => process.exit(0), 3000).unref(); // exit force after 3 seconds
|
package/src/large.ts
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { Collection } from "@wxn0brp/db-core/helpers/collection";
|
|
2
|
+
import { generatePosts } from "./generate";
|
|
3
|
+
import { bench, type BenchResult } from "./run";
|
|
4
|
+
|
|
5
|
+
const COUNT = 200_000;
|
|
6
|
+
|
|
7
|
+
export async function benchmarkLarge(
|
|
8
|
+
col: Collection,
|
|
9
|
+
onAfterAdd?: () => Promise<void>,
|
|
10
|
+
): Promise<BenchResult[]> {
|
|
11
|
+
const results: BenchResult[] = [];
|
|
12
|
+
const postData = generatePosts(COUNT);
|
|
13
|
+
const ids: string[] = [];
|
|
14
|
+
|
|
15
|
+
let i = 0;
|
|
16
|
+
results.push(
|
|
17
|
+
await bench(
|
|
18
|
+
"add-large",
|
|
19
|
+
async () => {
|
|
20
|
+
for (const p of postData) {
|
|
21
|
+
const doc = await col.add(p);
|
|
22
|
+
ids.push(doc._id);
|
|
23
|
+
i++;
|
|
24
|
+
if (i % 10000 === 0) console.log(`Added ${i} documents`);
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
COUNT,
|
|
28
|
+
),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (onAfterAdd) await onAfterAdd();
|
|
32
|
+
|
|
33
|
+
const firstId = ids[0];
|
|
34
|
+
const midId = ids[Math.floor(ids.length / 2)];
|
|
35
|
+
const lastId = ids[ids.length - 1];
|
|
36
|
+
|
|
37
|
+
results.push(
|
|
38
|
+
await bench("findOne-large", () =>
|
|
39
|
+
col.findOne({
|
|
40
|
+
_id: firstId,
|
|
41
|
+
}),
|
|
42
|
+
),
|
|
43
|
+
);
|
|
44
|
+
results.push(
|
|
45
|
+
await bench("find-search-large", () =>
|
|
46
|
+
col.find({
|
|
47
|
+
$gt: {
|
|
48
|
+
views: 9990,
|
|
49
|
+
},
|
|
50
|
+
}),
|
|
51
|
+
),
|
|
52
|
+
);
|
|
53
|
+
results.push(
|
|
54
|
+
await bench("find-paginated-large", () =>
|
|
55
|
+
col.find(
|
|
56
|
+
{},
|
|
57
|
+
{
|
|
58
|
+
limit: 100,
|
|
59
|
+
},
|
|
60
|
+
),
|
|
61
|
+
),
|
|
62
|
+
);
|
|
63
|
+
results.push(
|
|
64
|
+
await bench("updateOne-large", () =>
|
|
65
|
+
col.updateOne(
|
|
66
|
+
{
|
|
67
|
+
_id: midId,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
views: 999999,
|
|
71
|
+
},
|
|
72
|
+
),
|
|
73
|
+
),
|
|
74
|
+
);
|
|
75
|
+
results.push(
|
|
76
|
+
await bench("update-search-large", () =>
|
|
77
|
+
col.update(
|
|
78
|
+
{
|
|
79
|
+
$lt: {
|
|
80
|
+
views: 10,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
views: 999999,
|
|
85
|
+
},
|
|
86
|
+
),
|
|
87
|
+
),
|
|
88
|
+
);
|
|
89
|
+
results.push(
|
|
90
|
+
await bench("removeOne-large", () =>
|
|
91
|
+
col.removeOne({
|
|
92
|
+
_id: lastId,
|
|
93
|
+
}),
|
|
94
|
+
),
|
|
95
|
+
);
|
|
96
|
+
results.push(
|
|
97
|
+
await bench("remove-search-large", () =>
|
|
98
|
+
col.remove({
|
|
99
|
+
$gt: {
|
|
100
|
+
views: 9995,
|
|
101
|
+
},
|
|
102
|
+
}),
|
|
103
|
+
),
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
return results;
|
|
107
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { parseArgs } from "node:util";
|
|
2
|
+
|
|
3
|
+
export interface CliOptions {
|
|
4
|
+
smallOnly: boolean;
|
|
5
|
+
jsonOutput: boolean;
|
|
6
|
+
jsonFile: string;
|
|
7
|
+
adapterPathArg: string;
|
|
8
|
+
noCloud: boolean;
|
|
9
|
+
help: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function printHelp() {
|
|
13
|
+
console.log(`Usage: valthera-bench [adapter] [options]
|
|
14
|
+
|
|
15
|
+
Benchmark a ValtheraDB adapter.
|
|
16
|
+
|
|
17
|
+
Arguments:
|
|
18
|
+
adapter Path to adapter module
|
|
19
|
+
(default: ./valthera-e2e/index.ts)
|
|
20
|
+
|
|
21
|
+
Options:
|
|
22
|
+
-s, --small Run only the small collection benchmark
|
|
23
|
+
-j, --json Save results as JSON
|
|
24
|
+
-f, --jsonFile <path> JSON output file (default: results.json)
|
|
25
|
+
--no-cloud Skip comparison with cloud results
|
|
26
|
+
-h, --help Show this help`);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function parseCliOptions(): CliOptions {
|
|
30
|
+
const { values, positionals } = parseArgs({
|
|
31
|
+
options: {
|
|
32
|
+
small: {
|
|
33
|
+
type: "boolean",
|
|
34
|
+
short: "s",
|
|
35
|
+
},
|
|
36
|
+
json: {
|
|
37
|
+
type: "boolean",
|
|
38
|
+
short: "j",
|
|
39
|
+
},
|
|
40
|
+
jsonFile: {
|
|
41
|
+
type: "string",
|
|
42
|
+
short: "f",
|
|
43
|
+
},
|
|
44
|
+
"no-cloud": {
|
|
45
|
+
type: "boolean",
|
|
46
|
+
},
|
|
47
|
+
help: {
|
|
48
|
+
type: "boolean",
|
|
49
|
+
short: "h",
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
allowPositionals: true,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
smallOnly: values.small ?? false,
|
|
57
|
+
jsonOutput: Boolean(values.json || values.jsonFile),
|
|
58
|
+
jsonFile: values.jsonFile || "results.json",
|
|
59
|
+
adapterPathArg: positionals[0] || "./valthera-e2e/index.ts",
|
|
60
|
+
noCloud: values["no-cloud"] ?? false,
|
|
61
|
+
help: values.help ?? false,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { type BenchResult } from "../run";
|
|
2
|
+
|
|
3
|
+
const REPO = "wxn0brP/ValtheraDB-benchmark";
|
|
4
|
+
const RESULTS_BRANCH = "results";
|
|
5
|
+
|
|
6
|
+
export interface CloudEntry {
|
|
7
|
+
dir: string;
|
|
8
|
+
adapter: string;
|
|
9
|
+
runtime: string;
|
|
10
|
+
os: string;
|
|
11
|
+
results: BenchResult[];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface OpAverage {
|
|
15
|
+
avg: number;
|
|
16
|
+
count: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface CloudAverages {
|
|
20
|
+
overall: Map<string, OpAverage>;
|
|
21
|
+
adapters: Map<string, Map<string, OpAverage>>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
interface RawResultFile {
|
|
25
|
+
os?: string;
|
|
26
|
+
arch?: string;
|
|
27
|
+
node?: string;
|
|
28
|
+
bun?: string;
|
|
29
|
+
adapter?: string;
|
|
30
|
+
results: BenchResult[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function normalize(results: BenchResult[]): BenchResult[] {
|
|
34
|
+
const map = new Map<string, number[]>();
|
|
35
|
+
for (const r of results) {
|
|
36
|
+
const arr = map.get(r.name);
|
|
37
|
+
if (arr) arr.push(r.time);
|
|
38
|
+
else
|
|
39
|
+
map.set(r.name, [
|
|
40
|
+
r.time,
|
|
41
|
+
]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const out: BenchResult[] = [];
|
|
45
|
+
for (const [name, times] of map) {
|
|
46
|
+
out.push({
|
|
47
|
+
name,
|
|
48
|
+
time: times.reduce((a, b) => a + b, 0) / times.length,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function fetchCloudEntries(): Promise<CloudEntry[]> {
|
|
55
|
+
const treeRes = await fetch(
|
|
56
|
+
`https://api.github.com/repos/${REPO}/git/trees/${RESULTS_BRANCH}?recursive=1`,
|
|
57
|
+
{
|
|
58
|
+
headers: {
|
|
59
|
+
Accept: "application/vnd.github+json",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
if (!treeRes.ok) {
|
|
65
|
+
throw new Error(`GitHub API responded with ${treeRes.status}`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const treeData = await treeRes.json();
|
|
69
|
+
const paths: string[] = (treeData.tree ?? [])
|
|
70
|
+
.filter((item: any) => item.path.endsWith("/result.json"))
|
|
71
|
+
.map((item: any) => item.path);
|
|
72
|
+
|
|
73
|
+
return Promise.all(
|
|
74
|
+
paths.map(async path => {
|
|
75
|
+
const res = await fetch(
|
|
76
|
+
`https://raw.githubusercontent.com/${REPO}/${RESULTS_BRANCH}/${path}`,
|
|
77
|
+
);
|
|
78
|
+
if (!res.ok) {
|
|
79
|
+
throw new Error(`Failed to fetch ${path} (${res.status})`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const data: RawResultFile = await res.json();
|
|
83
|
+
const dir = path.split("/")[0];
|
|
84
|
+
const [adapter, runtime, os] = dir.split("__");
|
|
85
|
+
|
|
86
|
+
return {
|
|
87
|
+
dir,
|
|
88
|
+
adapter,
|
|
89
|
+
runtime,
|
|
90
|
+
os,
|
|
91
|
+
results: normalize(data.results ?? []),
|
|
92
|
+
};
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function addTimes(map: Map<string, number[]>, results: BenchResult[]) {
|
|
98
|
+
for (const r of results) {
|
|
99
|
+
const arr = map.get(r.name);
|
|
100
|
+
if (arr) arr.push(r.time);
|
|
101
|
+
else
|
|
102
|
+
map.set(r.name, [
|
|
103
|
+
r.time,
|
|
104
|
+
]);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function toAverages(times: Map<string, number[]>): Map<string, OpAverage> {
|
|
109
|
+
const out = new Map<string, OpAverage>();
|
|
110
|
+
for (const [op, values] of times) {
|
|
111
|
+
out.set(op, {
|
|
112
|
+
avg: values.reduce((a, b) => a + b, 0) / values.length,
|
|
113
|
+
count: values.length,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
return out;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export function buildCloudAverages(entries: CloudEntry[]): CloudAverages {
|
|
120
|
+
const overallTimes = new Map<string, number[]>();
|
|
121
|
+
const adapterTimes = new Map<string, Map<string, number[]>>();
|
|
122
|
+
|
|
123
|
+
for (const entry of entries) {
|
|
124
|
+
addTimes(overallTimes, entry.results);
|
|
125
|
+
|
|
126
|
+
let times = adapterTimes.get(entry.adapter);
|
|
127
|
+
if (!times) {
|
|
128
|
+
times = new Map();
|
|
129
|
+
adapterTimes.set(entry.adapter, times);
|
|
130
|
+
}
|
|
131
|
+
addTimes(times, entry.results);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const adapters = new Map<string, Map<string, OpAverage>>();
|
|
135
|
+
for (const [adapter, times] of adapterTimes) {
|
|
136
|
+
adapters.set(adapter, toAverages(times));
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return {
|
|
140
|
+
overall: toAverages(overallTimes),
|
|
141
|
+
adapters,
|
|
142
|
+
};
|
|
143
|
+
}
|