-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbenchmark.js
More file actions
executable file
·53 lines (49 loc) · 1.35 KB
/
benchmark.js
File metadata and controls
executable file
·53 lines (49 loc) · 1.35 KB
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
#! /usr/bin/env node
let html = `
<html><head>
<meta name="hello" content="world">
<meta name="hello" content="moon">
</head><body>
<div><h1>Hello, world!</h1></div>
</body></html>
`
const Benchmark = require('benchmark')
const got = require('got')
const htmlTagParser = require('html-tag-parser')
const cheerio = require('cheerio')
const htmlparser2 = require('htmlparser2')
const htmlParseStringify2 = require('html-parse-stringify2')
const fastHtml = require('fast-html')
const parse5 = require('parse5')
const hypertag = require('./hypertag.js')
const suite = (new Benchmark.Suite())
.add('hypertag', () => {
hypertag(html, 'meta')
})
.add('fast-html', () => {
fastHtml({parseAttributes: true}).parse(html)
})
.add('parse5', () => parse5.parse(html))
.add('htmlparser2', () => {
const parser = new htmlparser2.Parser()
parser.parseComplete(html)
})
.add('html-tag-parser', () => {
htmlTagParser(html, 'meta')
})
.add('cheerio', () => {
cheerio.load(html)('meta')
})
.add('html-parse-stringify2', () => {
htmlParseStringify2.parse(html)
})
.on('cycle', event => {
console.log(String(event.target))
})
.on('complete', function () {
console.log('Fastest is ' + this.filter('fastest').map('name'))
})
got('https://apple.com/').then(result => {
html = result.body
suite.run({async: true})
})