-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate-bucket-calc-chart.ts
More file actions
165 lines (149 loc) · 4.64 KB
/
Copy pathgenerate-bucket-calc-chart.ts
File metadata and controls
165 lines (149 loc) · 4.64 KB
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
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env bun
import fs from "fs"
import path from "path"
import vega from "./shebang-scripts/node_modules/vega"
import vl from "./shebang-scripts/node_modules/vega-lite"
// Load data from the JSON file
const data = JSON.parse(
fs.readFileSync(
path.join(import.meta.dirname, "bucket-calc/result.json"),
"utf8",
),
)
function parseResult(command: string): { name: string; type: string } {
// Compiled binaries
if (command.startsWith("./output/bucket_calc/main-")) {
return {
name: command.replace("./output/bucket_calc/main-", ""),
type: "compiled",
}
}
if (command.startsWith("java -cp output/bucket_calc/")) {
return { name: "java", type: "compiled" }
}
// Interpreted - special cases with flags, subcommands, or disambiguation
const specialCases: Record<string, string> = {
'sqlite3 :memory: -init bucket-calc/main.sql ""': "sqlite",
'typst query --field=text --one bucket-calc/main.typ "<main>"': "typst",
"nix eval --file bucket-calc/main.nix": "nix",
"java --source 11 compiled/bucket_calc/Main.java": "java-source",
"nim r --hints:off compiled/bucket_calc/main.nim": "nim-r",
"nickel export bucket-calc/main.ncl": "nickel",
"woxi run bucket-calc/main-woxi.wls": "woxi",
"dotnet fsi bucket-calc/main.fsx": "fsharp",
"guile -s bucket-calc/main.scm": "guile",
"jq -n -f bucket-calc/main.jq": "jq",
"deno run bucket-calc/main.ts": "deno-ts",
"deno run bucket-calc/main.js": "deno-js",
"bun run bucket-calc/main.ts": "bun-ts",
"bun run bucket-calc/main.js": "bun-js",
"dart run bucket-calc/main.dart": "dart",
"v run compiled/bucket_calc/main.v": "v-run",
"uiua run bucket-calc/main.ua": "uiua",
"scala-cli run bucket-calc/main.scala": "scala",
"runhaskell compiled/bucket_calc/Main.hs": "runhaskell",
"ocaml compiled/bucket_calc/main.ml": "ocaml-script",
"rust-script compiled/bucket_calc/main.rs": "rust-script",
}
if (specialCases[command]) {
return { name: specialCases[command], type: "interpreted" }
}
// Interpreted - generic: "interpreter bucket-calc/main.ext"
const genericMatch = command.match(/\s*bucket-calc\/\S+/g)
if (genericMatch) {
return {
name: command.replace(/\s*bucket-calc\/\S+/g, "").trim(),
type: "interpreted",
}
}
// Interpreted - generic: "interpreter compiled/bucket_calc/main.ext"
const compiledMatch = command.match(/\s*compiled\/bucket_calc\/\S+/g)
if (compiledMatch) {
return {
name: command.replace(/\s*compiled\/bucket_calc\/\S+/g, "").trim(),
type: "interpreted",
}
}
// Fallback
return { name: command.split(" ")[0], type: "interpreted" }
}
// Extract data from the JSON
const df: {
command: string
type: string
mean_time: number
relative_speed: number
}[] = data.results.map((result) => {
const { name, type } = parseResult(result.command)
return {
command: name,
type,
mean_time: result.mean,
relative_speed: 0,
}
})
// Find the fastest entry (smallest mean_time)
const fastestEntry = df.reduce((min, entry) => {
return entry.mean_time < min.mean_time ? entry : min
}, df[0])
const fastestCommand = fastestEntry.command
const fastestTime: number = fastestEntry.mean_time
// Calculate times faster relative to the fastest entry
df.forEach((entry) => {
entry.relative_speed = fastestTime / entry.mean_time
})
// Sort the DataFrame by relative_speed
df.sort((a, b) => b.relative_speed - a.relative_speed)
console.log(df)
// Define the Vega-Lite chart specification
const spec = {
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
title: `Bucket Calc - Relative Execution Speed (Higher is Better)`,
mark: "bar",
width: 800,
height: 400,
encoding: {
x: {
field: "command",
type: "nominal",
sort: "-y",
title: "Command",
axis: {
labelAngle: -45,
},
},
y: {
field: "relative_speed",
type: "quantitative",
title: `Relative Speed in Comparison to ${fastestCommand}`,
},
color: {
field: "type",
type: "nominal",
title: "Type",
scale: {
domain: ["compiled", "interpreted"],
range: ["steelblue", "coral"],
},
},
tooltip: [
{ field: "command" },
{ field: "type" },
{ field: "relative_speed" },
],
},
data: {
values: df,
},
}
// Create a Vega view for rendering
const runtime = vl.compile(spec).spec
const view = new vega.View(vega.parse(runtime), { renderer: "none" })
// Export to SVG
view.toSVG().then((svg) => {
fs.writeFileSync(
path.join(import.meta.dirname, "bucket-calc/chart.svg"),
svg,
)
console.log("Bucket calc chart generated successfully!")
})