Skip to content

Commit 19731f0

Browse files
committed
better formatting
1 parent 8ea5c2b commit 19731f0

File tree

4 files changed

+273
-8
lines changed

4 files changed

+273
-8
lines changed

db-service/bench/cqn4sql/performance-benchmarks.test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const cds = require('@sap/cds')
4+
const { writeDump } = require('./utils/format-bench')
45

56
let cqn4sql = require('../../lib/cqn4sql')
67

@@ -17,6 +18,10 @@ describe('cqn4sql performance benchmarks', () => {
1718
cqn4sql = q => orig(q, m)
1819
})
1920

21+
after('format & write dump', () => {
22+
writeDump({ testFile: __filename })
23+
})
24+
2025
runBenchmarkFor('select simple', cds.ql`SELECT from my.Books { ID }`)
2126

2227
runBenchmarkFor('expand simple', cds.ql`SELECT from my.Authors { ID, books { title } }`)
@@ -34,5 +39,5 @@ describe('cqn4sql performance benchmarks', () => {
3439
function runBenchmarkFor(name, cqn) {
3540
it(name, async () => report(await perf.fn(() => {
3641
cqn4sql(cqn)
37-
}), { title: name }))
42+
}, { title: name })))
3843
}

db-service/bench/cqn4sql/results.bench

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
{
2+
"8ea5c2b9": {
3+
"date": "2025-08-27T15:03:45.583Z",
4+
"benchmarks": {
5+
"select simple": {
6+
"average": 87328,
7+
"mean": 87328,
8+
"stddev": 64,
9+
"min": 87254,
10+
"max": 87407,
11+
"total": 262221,
12+
"p0_001": 87295,
13+
"p0_01": 87295,
14+
"p0_1": 87295,
15+
"p1": 87295,
16+
"p2_5": 87295,
17+
"p10": 87295,
18+
"p25": 87295,
19+
"p50": 87295,
20+
"p75": 87423,
21+
"p90": 87423,
22+
"p97_5": 87423,
23+
"p99": 87423,
24+
"p99_9": 87423,
25+
"p99_99": 87423,
26+
"p99_999": 87423,
27+
"sent": 262221
28+
},
29+
"expand simple": {
30+
"average": 20440,
31+
"mean": 20440,
32+
"stddev": 608,
33+
"min": 19829,
34+
"max": 21042,
35+
"total": 61476,
36+
"p0_001": 19839,
37+
"p0_01": 19839,
38+
"p0_1": 19839,
39+
"p1": 19839,
40+
"p2_5": 19839,
41+
"p10": 19839,
42+
"p25": 19839,
43+
"p50": 19839,
44+
"p75": 21055,
45+
"p90": 21055,
46+
"p97_5": 21055,
47+
"p99": 21055,
48+
"p99_9": 21055,
49+
"p99_99": 21055,
50+
"p99_999": 21055,
51+
"sent": 61476
52+
},
53+
"expand recursive (depth 3)": {
54+
"average": 7926,
55+
"mean": 7926,
56+
"stddev": 252,
57+
"min": 7673,
58+
"max": 8176,
59+
"total": 23912,
60+
"p0_001": 7675,
61+
"p0_01": 7675,
62+
"p0_1": 7675,
63+
"p1": 7675,
64+
"p2_5": 7675,
65+
"p10": 7675,
66+
"p25": 7675,
67+
"p50": 7675,
68+
"p75": 8179,
69+
"p90": 8179,
70+
"p97_5": 8179,
71+
"p99": 8179,
72+
"p99_9": 8179,
73+
"p99_99": 8179,
74+
"p99_999": 8179,
75+
"sent": 23912
76+
},
77+
"exists simple": {
78+
"average": 8144,
79+
"mean": 8144,
80+
"stddev": 26,
81+
"min": 8117,
82+
"max": 8168,
83+
"total": 24353,
84+
"p0_001": 8119,
85+
"p0_01": 8119,
86+
"p0_1": 8119,
87+
"p1": 8119,
88+
"p2_5": 8119,
89+
"p10": 8119,
90+
"p25": 8119,
91+
"p50": 8119,
92+
"p75": 8171,
93+
"p90": 8171,
94+
"p97_5": 8171,
95+
"p99": 8171,
96+
"p99_9": 8171,
97+
"p99_99": 8171,
98+
"p99_999": 8171,
99+
"sent": 24353
100+
},
101+
"exists recursive (depth 3)": {
102+
"average": 46192,
103+
"mean": 46192,
104+
"stddev": 224,
105+
"min": 45979,
106+
"max": 46426,
107+
"total": 139422,
108+
"p0_001": 45983,
109+
"p0_01": 45983,
110+
"p0_1": 45983,
111+
"p1": 45983,
112+
"p2_5": 45983,
113+
"p10": 45983,
114+
"p25": 45983,
115+
"p50": 45983,
116+
"p75": 46431,
117+
"p90": 46431,
118+
"p97_5": 46431,
119+
"p99": 46431,
120+
"p99_9": 46431,
121+
"p99_99": 46431,
122+
"p99_999": 46431,
123+
"sent": 139422
124+
},
125+
"assoc2join simple": {
126+
"average": 53792,
127+
"mean": 53792,
128+
"stddev": 1328,
129+
"min": 52462,
130+
"max": 55129,
131+
"total": 159915,
132+
"p0_001": 52479,
133+
"p0_01": 52479,
134+
"p0_1": 52479,
135+
"p1": 52479,
136+
"p2_5": 52479,
137+
"p10": 52479,
138+
"p25": 52479,
139+
"p50": 52479,
140+
"p75": 55135,
141+
"p90": 55135,
142+
"p97_5": 55135,
143+
"p99": 55135,
144+
"p99_9": 55135,
145+
"p99_99": 55135,
146+
"p99_999": 55135,
147+
"sent": 159915
148+
},
149+
"assoc2join recursive (depth 3)": {
150+
"average": 42480,
151+
"mean": 42480,
152+
"stddev": 384,
153+
"min": 42091,
154+
"max": 42872,
155+
"total": 128504,
156+
"p0_001": 42111,
157+
"p0_01": 42111,
158+
"p0_1": 42111,
159+
"p1": 42111,
160+
"p2_5": 42111,
161+
"p10": 42111,
162+
"p25": 42111,
163+
"p50": 42111,
164+
"p75": 42879,
165+
"p90": 42879,
166+
"p97_5": 42879,
167+
"p99": 42879,
168+
"p99_9": 42879,
169+
"p99_99": 42879,
170+
"p99_999": 42879,
171+
"sent": 128504
172+
}
173+
}
174+
}
175+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
'use strict'
2+
3+
const fs = require('fs')
4+
const path = require('path')
5+
const { execSync } = require('child_process')
6+
7+
function getCommitShort() {
8+
try {
9+
return execSync('git rev-parse --short HEAD', { stdio: ['ignore', 'pipe', 'ignore'] })
10+
.toString()
11+
.trim()
12+
} catch {
13+
const sha = process.env.GITHUB_SHA || process.env.CI_COMMIT_SHA || ''
14+
return sha ? sha.slice(0, 7) : `unknown-${new Date().toISOString().replace(/[:.]/g, '-')}`
15+
}
16+
}
17+
18+
function collectBenchmarksForFile(resultsPath, testFileBase) {
19+
const lines = fs.existsSync(resultsPath) ? fs.readFileSync(resultsPath, 'utf8').split(/\r?\n/).filter(Boolean) : []
20+
21+
const benchmarks = {}
22+
for (const line of lines) {
23+
let obj
24+
try {
25+
obj = JSON.parse(line)
26+
} catch {
27+
continue
28+
}
29+
const key = Object.keys(obj)[0]
30+
const data = obj[key]
31+
if (!data) continue
32+
33+
const fromThisFile = data.file === testFileBase || (typeof key === 'string' && key.startsWith(`${testFileBase}:`))
34+
if (!fromThisFile) continue
35+
36+
const title = data.title || key.split(':')[1] || key
37+
if (data.requests) benchmarks[title] = data.requests // keep only "requests"
38+
}
39+
return benchmarks
40+
}
41+
42+
/**
43+
* Formats & writes the cumulative dump:
44+
* dump[commit] = { date, benchmarks }
45+
*
46+
* @param {object} opts
47+
* @param {string} opts.testFile absolute __filename of the calling test
48+
* @param {string} [opts.resultsFile='results.bench']
49+
* @param {string} [opts.dumpFile='perf-benchmarks.json']
50+
* @returns {false | {commit:string,file:string,count:number}}
51+
*/
52+
function writeDump({
53+
testFile,
54+
resultsFile = 'results.bench',
55+
dumpFile = 'cqn4sql-benchmarks.json',
56+
deleteResultsFile = true,
57+
}) {
58+
const testFileBase = path.basename(testFile)
59+
const resultsPath = path.resolve(process.cwd(), resultsFile)
60+
const dumpPath = path.resolve(process.cwd() + '/results', dumpFile)
61+
62+
const benchmarks = collectBenchmarksForFile(resultsPath, testFileBase)
63+
if (!Object.keys(benchmarks).length) return false
64+
65+
const commit = getCommitShort()
66+
const entry = { date: new Date().toISOString(), benchmarks }
67+
68+
let dump = {}
69+
if (fs.existsSync(dumpPath)) {
70+
try {
71+
dump = JSON.parse(fs.readFileSync(dumpPath, 'utf8')) || {}
72+
} catch {
73+
dump = {}
74+
}
75+
}
76+
dump[commit] = entry
77+
78+
fs.mkdirSync(path.dirname(dumpPath), { recursive: true })
79+
fs.writeFileSync(dumpPath, JSON.stringify(dump, null, 2) + '\n', 'utf8')
80+
81+
if (deleteResultsFile && fs.existsSync(resultsPath)) {
82+
try {
83+
fs.unlinkSync(resultsPath)
84+
} catch {
85+
/* ignore */
86+
}
87+
}
88+
89+
return { commit, file: dumpPath, count: Object.keys(benchmarks).length }
90+
}
91+
92+
module.exports = { writeDump }

0 commit comments

Comments
 (0)