-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
huge-schema.bench.ts
92 lines (86 loc) · 2.57 KB
/
huge-schema.bench.ts
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
// @ts-nocheck
import { withCodSpeed } from '@codspeed/benchmark.js-plugin'
import Benchmark from 'benchmark'
import execa from 'execa'
import fs from 'fs'
import path from 'path'
import { compileFile } from '../../../utils/compileFile'
import { generateTestClient } from '../../../utils/getTestClient'
const suite = withCodSpeed(new Benchmark.Suite('typescript'))
// @ts-ignore
// eslint-disable-next-line @typescript-eslint/no-floating-promises
suite
.add('client generation ~50 Models', {
defer: true,
fn: function (deferred) {
generateTestClient(__dirname)
.then(() => {
deferred.resolve()
})
.catch((err) => {
console.error(err)
process.exit(1)
})
},
})
.add('typescript compilation ~50 Models', {
defer: true,
fn: function (deferred) {
compileFile(path.join(__dirname, './compile.ts'))
.then(() => {
deferred.resolve()
})
.catch((err) => {
console.error(err)
process.exit(1)
})
},
})
.on('cycle', (event) => {
// Output benchmark result by converting benchmark result to string
console.log(String(event.target))
})
.on('complete', () => {
printSize('./node_modules/@prisma/client')
printSize('./node_modules/.prisma/client')
printSize('./node_modules/.prisma/client/index.d.ts')
printSize('./node_modules/.prisma/client/index.js')
// For GitHub CI
if (process.env.CI) {
printSize('./node_modules/.prisma/client/libquery_engine-debian-openssl-1.1.x.so.node')
}
execa.sync('rm', ['-rf', `./dotPlusAtPrismaClientFolder.zip`], {
stdout: 'pipe',
cwd: __dirname,
})
execa.sync(
'zip',
['-r', 'dotPlusAtPrismaClientFolder.zip', './node_modules/.prisma/client', './node_modules/@prisma/client'],
{
stdout: 'pipe',
cwd: __dirname,
},
)
printSize('./dotPlusAtPrismaClientFolder.zip')
})
.run()
function printSize(targetPath: string): void {
const size = getSize(path.join(__dirname, targetPath)) / 1024 / 1024
console.log(
`${targetPath.replace('./node_modules/', '').replace('./', '')} size x ${size} MB ±0.00% (1 runs sampled)`,
)
}
function getSize(targetPath: string): number {
const stat = fs.statSync(targetPath)
if (stat.isFile()) {
return stat.size
}
if (stat.isDirectory()) {
return fs
.readdirSync(targetPath)
.filter((fileName) => fileName !== '.' && fileName !== '..')
.map((subPath) => getSize(path.join(targetPath, subPath)))
.reduce((a, b) => a + b)
}
return 0
}