Skip to content

Commit 121cc44

Browse files
author
Bart Veneman
committed
add memory benchmark
1 parent 5014f2a commit 121cc44

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

benchmark/memory.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import byteSize from './format-filesize.js'
2+
import { analyze as analyzeCss } from '../dist/analyzer.modern.js'
3+
import * as fs from 'fs'
4+
const files = [
5+
['bol-com-20190617', 'Bol.com', 117],
6+
['bootstrap-5.0.0', 'Bootstrap 5.0.0', 49],
7+
['css-tricks-20190319', 'CSS-Tricks', 50],
8+
['cnn-20220403', 'CNN', 360],
9+
['facebook-20190319', 'Facebook.com', 71],
10+
['github-20210501', 'GitHub.com', 95],
11+
['gazelle-20210905', 'Gazelle.nl', 312],
12+
['lego-20190617', 'Lego.com', 59],
13+
['smashing-magazine-20190319', 'Smashing Magazine.com', 285],
14+
['trello-20190617', 'Trello.com', 80]
15+
]
16+
17+
let maxLen = -1
18+
19+
files.forEach(([, name]) => {
20+
if (name.length > maxLen) {
21+
maxLen = name.length
22+
}
23+
})
24+
25+
console.log('Running benchmark on /dist/analyzer.js:')
26+
27+
const suite = []
28+
29+
files.forEach(([filename, name, expectedDuration]) => {
30+
const css = fs.readFileSync(`./src/__fixtures__/${filename}.css`, 'utf-8')
31+
const fileSize = byteSize(css.length)
32+
suite.push([
33+
`${name.padEnd(maxLen + 2)} (${fileSize.padStart(7)})`,
34+
() => analyzeCss(css),
35+
`${(process.memoryUsage().heapUsed / 1024 / 1024).toFixed(3)}MB`
36+
])
37+
})
38+
39+
suite.forEach(([name, fn, memory]) => {
40+
const start = new Date()
41+
fn()
42+
const duration = (new Date() - start)
43+
console.log(
44+
name,
45+
`${duration}ms`.padStart(6, ' '),
46+
memory,
47+
)
48+
})
49+

0 commit comments

Comments
 (0)