Skip to content

Commit 0773f88

Browse files
authored
Move some analysis to main loop (#225)
1 parent 71a2b1b commit 0773f88

File tree

9 files changed

+347
-328
lines changed

9 files changed

+347
-328
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ node_modules
22
.nyc_output
33
coverage
44
.DS_Store
5-
dist
5+
dist
6+
.vscode

benchmark/run.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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', 127],
6+
['bootstrap-5.0.0', 'Bootstrap 5.0.0', 49],
7+
['css-tricks-20190319', 'CSS-Tricks', 50],
8+
['facebook-20190319', 'Facebook.com', 75],
9+
['github-20210501', 'GitHub.com', 95],
10+
['gazelle-20210905', 'Gazelle.nl', 325],
11+
['lego-20190617', 'Lego.com', 62],
12+
['smashing-magazine-20190319', 'Smashing Magazine.com', 300],
13+
['trello-20190617', 'Trello.com', 86]
14+
]
15+
16+
let maxLen = -1
17+
18+
files.forEach(([, name]) => {
19+
if (name.length > maxLen) {
20+
maxLen = name.length
21+
}
22+
})
23+
24+
console.log('Running benchmark on /dist/analyzer.js:')
25+
26+
const suite = []
27+
28+
files.forEach(([filename, name, expectedDuration]) => {
29+
const css = fs.readFileSync(`./src/__fixtures__/${filename}.css`, 'utf-8')
30+
const fileSize = byteSize(css.length)
31+
suite.push([
32+
`${name.padEnd(maxLen + 2)} (${fileSize.padStart(6)})`,
33+
() => analyzeCss(css),
34+
expectedDuration
35+
])
36+
})
37+
38+
const RUN_COUNT = 20
39+
40+
suite.forEach(([name, fn, expectedDuration]) => {
41+
const start = new Date()
42+
for (let i = 0; i < RUN_COUNT; i++) {
43+
fn();
44+
}
45+
const duration = Math.floor((new Date() - start) / RUN_COUNT)
46+
const overtime = expectedDuration - duration
47+
console.log(
48+
name,
49+
`${duration}ms`.padStart(6, ' '),
50+
`(${overtime >= 0 ? '-' : '+'}${Math.abs(overtime)}ms ${Math.round(Math.abs(overtime) / duration * 100)}%)`
51+
)
52+
})

src/aggregate-collection.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class AggregateCollection {
8282
const max = sorted[sorted.length - 1]
8383

8484
const sum = this.items.reduce((total, num) => (total += num))
85-
const mode = Mode(sorted)
85+
const mode = Mode(this.items)
8686
const median = Median(sorted)
8787

8888
return {

src/context-collection.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ class ContextCollection {
55
this.list = new CountableCollection()
66
/** @type {[index; string]: CountableCollection} */
77
this.contexts = {}
8-
this.contextCount = 0
98
}
109

1110
/**
@@ -18,7 +17,6 @@ class ContextCollection {
1817

1918
if (!this.contexts[context]) {
2019
this.contexts[context] = new CountableCollection()
21-
this.contextCount++
2220
}
2321

2422
this.contexts[context].push(item)

src/declarations/declarations.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)