Skip to content

Commit 7acec25

Browse files
committed
test: report size/gzip size in multi-byte table builder
1 parent ec3fd27 commit 7acec25

File tree

1 file changed

+11
-3
lines changed
  • tests/encoding/fixtures/multi-byte

1 file changed

+11
-3
lines changed

tests/encoding/fixtures/multi-byte/dump.js

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { toBase64url } from '@exodus/bytes/base64.js'
33
import { utf16fromString } from '@exodus/bytes/utf16.js'
44
import { join } from 'node:path'
55
import assert from 'node:assert/strict'
6+
import { gzipSync } from 'node:zlib'
67

78
// const splitChunks = new Set(['jis0208', 'jis0212', 'big5']) // pretty-print into chunks, non-continious anyway
89

@@ -42,7 +43,7 @@ for (const file of readdirSync(import.meta.dirname)) {
4243
const match = file.match(/^index-([a-z0-9-]+)\.txt$/u)
4344
if (!match) continue
4445
const encoding = match[1]
45-
if (encoding.endsWith('-ranges')) continue
46+
if (encoding.endsWith('-ranges') || encoding === 'iso-2022-jp-katakana ') continue
4647
const non16bit = encoding === 'big5'
4748
const text = readFileSync(join(import.meta.dirname, file), 'utf8')
4849
let max = 0
@@ -127,6 +128,7 @@ function encodeString(s, lastconseq) {
127128
return str.length * 1.5 < partsstr.length && str.length < partsstr.length - 3 ? [str] : parts
128129
}
129130

131+
let final = '{\n'
130132
for (const [encoding, chars] of Object.entries(encodings)) {
131133
const list = []
132134
let str = chars
@@ -222,7 +224,13 @@ for (const [encoding, chars] of Object.entries(encodings)) {
222224
if (tmp.length > 0) list2.push(tmp)
223225

224226
const dump = list2.join(',\n ')
225-
console.log(`const ${encoding} = [\n ${dump}\n]\n`)
227+
final += ` ${JSON.stringify(encoding)}: [\n ${dump}\n ],\n`
226228
}
227229

228-
console.error([...stats].sort((a, b) => b[1] - a[1]))
230+
final += '}'
231+
232+
// console.error([...stats].sort((a, b) => b[1] - a[1]))
233+
234+
console.log(final)
235+
console.error(`Raw size: ${final.length}`)
236+
console.error(`Gzip size: ${gzipSync(final).length}`)

0 commit comments

Comments
 (0)