Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions benchmark-record.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,11 @@ export function formatJson(value) {
return (
JSON.stringify(value, null, 2).replace(
/^( *)(.*)\[\n((?:\1 {2}(?:-?[\d.e+-]+|"[^"\n]*"|null),?\n)+)\1\]/gm,
(whole, indent, key, items) => {
(whole, indent, key, items, offset, json) => {
const values = items.trim().split(/,\n */)
const line = `${indent}${key}[${values.join(', ')}]`
if (line.length + 1 <= PRINT_WIDTH) return line
const comma = json[offset + whole.length] === ',' ? 1 : 0
if (line.length + comma <= PRINT_WIDTH) return line
return values.every((item) => /^-?[\d.e+-]+$/.test(item))
? fillNumbers(indent, key, values)
: whole
Expand Down
4 changes: 1 addition & 3 deletions benchmark/history.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,7 @@
"devup-ui-large": [15.099, 15.029, 15.117, 88882994, 1388, 934329],
"devup-ui-large-wasm": [16.233, 16.017, 16.28, 89000421, 1388, 934329],
"devup-ui-large-turbo": [6.037, 5.938, 6.244, 38676786, 1512, 571629],
"devup-ui-large-turbo-wasm": [
6.5, 6.483, 6.542, 38662174, 1512, 571629
]
"devup-ui-large-turbo-wasm": [6.5, 6.483, 6.542, 38662174, 1512, 571629]
}
},
{
Expand Down
12 changes: 12 additions & 0 deletions packages/plugin-utils/src/__tests__/benchmark-record.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,18 @@ describe('benchmark JSON', () => {
)
})

it('fits a last array of 80 columns on one line, as it takes no comma', () => {
// Exactly 80 columns, 81 when a comma follows
const values = [1.5, 2.25, 3.125, 38662174, 1512, 571629, 12345678, 1234]
const fits = { aaaaaaaaaaaaaaaa: values }
const split = { aaaaaaaaaaaaaaaa: values, b: 1 }
const line = ` "aaaaaaaaaaaaaaaa": [${values.join(', ')}]`

expect(line).toHaveLength(80)
expect(formatJson(fits)).toBe(`{\n${line}\n}\n`)
expect(formatJson(split).split('\n')[1]).toBe(' "aaaaaaaaaaaaaaaa": [')
})

it('formats the checked files exactly as it writes them', () => {
for (const file of ['benchmark-results.json', 'benchmark/history.json']) {
const text = readFileSync(join(ROOT, file), 'utf8').replaceAll(
Expand Down
Loading