-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbench.js
155 lines (140 loc) · 3.33 KB
/
bench.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
import { createCanvas } from "https://deno.land/x/[email protected]/mod.ts";
import "https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.min.js";
import "https://cdn.jsdelivr.net/npm/[email protected]/dist/chartjs-plugin-datalabels.min.js";
Chart.register(ChartDataLabels);
function $(name) {
const lines = new TextDecoder().decode(
Deno.spawnSync(Deno.execPath(), {
args: ["task", name],
env: {
NO_COLOR: "1",
},
stdout: "piped",
}).stdout,
)
.split("\n")
.map((line) => line.trim())
.filter((line) => line.includes(" rate "));
const all = lines.map((e) => Number(e.split(" rate ")[1]));
return all.reduce((p, a) => p + a, 0) / all.length;
}
console.log("Running C benchmark...");
const cOut = $("bench-c");
console.log("C Avg:", cOut);
console.log("Running Deno benchmark...");
const denoOut = $("bench-deno");
console.log("Deno Avg:", denoOut);
console.log("Running Deno Wasm benchmark...");
const denoWasmOut = $("bench-deno-wasm");
console.log("Deno Wasm Avg:", denoWasmOut);
console.log("Running Deno FFI benchmark...");
const denoFfiOut = $("bench-deno-ffi");
console.log("Deno FFI Avg:", denoFfiOut);
console.log("Running Node benchmark...");
const nodeOut = $("bench-node");
console.log("Node Avg:", nodeOut);
console.log("Running Bun benchmark...");
const bunOut = $("bench-bun");
console.log("Bun Avg:", bunOut);
console.log("Running Bun FFI benchmark...");
const bunFfiOut = $("bench-bun-ffi");
console.log("Bun FFI Avg:", bunFfiOut);
console.log("Running Python benchmark...");
const pyOut = $("bench-python");
console.log("Python Avg:", pyOut);
const data = {
labels: [
"C",
"Deno FFI",
"x/sqlite3 (FFI)",
"x/sqlite (WASM)",
"better-sqlite3",
"bun:ffi",
"bun:sqlite",
"python sqlite",
],
datasets: [{
label: "Performance",
data: [
cOut,
denoFfiOut,
denoOut,
denoWasmOut,
nodeOut,
bunFfiOut,
bunOut,
pyOut,
],
backgroundColor: [
"#8dc149",
"#4285f4",
"#ea4336",
"#fbbb07",
"#34a753",
"#ff6d01",
"#5d5986",
"#417996",
],
borderWidth: 0,
borderRadius: 6,
}],
};
const canvas = createCanvas(800, 600);
const ctx = canvas.getContext("2d");
console.log("Rendering chart...");
const _chart = new Chart(ctx, {
type: "bar",
data,
options: {
plugins: {
title: {
display: true,
text: `SQLite Benchmark`,
},
subtitle: {
display: true,
text: `Higher is better`,
},
datalabels: {
anchor: "end",
align: "top",
formatter: Math.round,
font: {
weight: "normal",
size: 14,
},
},
},
scales: {
y: {
beginAtZero: true,
title: {
display: true,
text: "ops/sec",
},
},
x: {
title: {
display: true,
text: "module",
},
},
},
responsive: false,
animation: false,
},
plugins: [
{
id: "custom_canvas_background_color",
beforeDraw: (chart) => {
const { ctx } = chart;
ctx.save();
ctx.fillStyle = "white";
ctx.fillRect(0, 0, chart.width, chart.height);
ctx.restore();
},
},
],
});
canvas.save("bench/results.png");
console.log("Done!");