Publish
This commit is contained in:
25
task/benchmark/compression/index.ts
Normal file
25
task/benchmark/compression/index.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { shell } from '@sinclair/hammer'
|
||||
import { statSync, readdirSync } from 'fs'
|
||||
import { basename, extname } from 'path'
|
||||
|
||||
export async function measure(test: string) {
|
||||
await shell(`hammer build task/benchmark/compression/module/${test}.ts --dist target/benchmark/compression`)
|
||||
const compiled = statSync(`target/benchmark/compression/${test}.js`)
|
||||
await shell(`hammer build task/benchmark/compression/module/${test}.ts --dist target/benchmark/compression --minify`)
|
||||
const minified = statSync(`target/benchmark/compression/${test}.js`)
|
||||
return {
|
||||
test: test.padEnd(20),
|
||||
compiled: `${(compiled.size / 1000).toFixed(1)} kb`.padStart(8),
|
||||
minified: `${(minified.size / 1000).toFixed(1)} kb`.padStart(8),
|
||||
ratio: compiled.size / minified.size,
|
||||
}
|
||||
}
|
||||
|
||||
export async function compression() {
|
||||
const tests = readdirSync('task/benchmark/compression/module').map((name) => basename(name, extname(name)))
|
||||
const results = await Promise.all(tests.map((test) => measure(test)))
|
||||
const present = results.reduce((acc, c) => {
|
||||
return { ...acc, [c.test.replace(/-/g, '/')]: { Compiled: c.compiled, Minified: c.minified, Compression: `${c.ratio.toFixed(2)} x` } }
|
||||
}, {})
|
||||
console.table(present)
|
||||
}
|
||||
3
task/benchmark/compression/module/typebox-compiler.ts
Normal file
3
task/benchmark/compression/module/typebox-compiler.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { TypeCompiler } from '@sinclair/typebox/compiler'
|
||||
|
||||
console.log(TypeCompiler)
|
||||
3
task/benchmark/compression/module/typebox-errors.ts
Normal file
3
task/benchmark/compression/module/typebox-errors.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import * as Errors from '@sinclair/typebox/errors'
|
||||
|
||||
console.log(Errors)
|
||||
3
task/benchmark/compression/module/typebox-syntax.ts
Normal file
3
task/benchmark/compression/module/typebox-syntax.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import * as Syntax from '@sinclair/typebox/syntax'
|
||||
|
||||
console.log(Syntax)
|
||||
3
task/benchmark/compression/module/typebox-system.ts
Normal file
3
task/benchmark/compression/module/typebox-system.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { TypeSystem } from '@sinclair/typebox/system'
|
||||
|
||||
console.log(TypeSystem)
|
||||
3
task/benchmark/compression/module/typebox-value.ts
Normal file
3
task/benchmark/compression/module/typebox-value.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Value } from '@sinclair/typebox/value'
|
||||
|
||||
console.log(Value)
|
||||
3
task/benchmark/compression/module/typebox.ts
Normal file
3
task/benchmark/compression/module/typebox.ts
Normal file
@@ -0,0 +1,3 @@
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
const T = Type.String()
|
||||
Reference in New Issue
Block a user