-
-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
1,427 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,345 changes: 1,345 additions & 0 deletions
1,345
packages/metascraper-readability/benchmark/fixture.html
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict' | ||
|
||
const { readFileSync } = require('fs') | ||
|
||
const url = 'https://arxiv.org/pdf/2412.06592' | ||
const html = readFileSync('./fixture.html', 'utf8') | ||
|
||
const jsdom = () => { | ||
const { JSDOM, VirtualConsole } = require('jsdom') | ||
const dom = new JSDOM(html, { url, virtualConsole: new VirtualConsole() }) | ||
return dom.window.document | ||
} | ||
|
||
const happydom = () => { | ||
const { Window } = require('happy-dom') | ||
const window = new Window({ url }) | ||
const document = window.document | ||
document.documentElement.innerHTML = html | ||
return document | ||
} | ||
|
||
const { Readability } = require('@mozilla/readability') | ||
|
||
const measure = fn => { | ||
const now = Date.now() | ||
const parsed = new Readability(fn()).parse() | ||
return { parsed, duration: Date.now() - now } | ||
} | ||
|
||
const jsdomResult = measure(jsdom) | ||
const happydomResult = measure(happydom) | ||
|
||
const isEqual = (value1, value2) => | ||
JSON.stringify(value1) === JSON.stringify(value2) | ||
|
||
if (!isEqual(jsdomResult.parsed, happydomResult.parsed)) { | ||
console.error('Results are different') | ||
process.exit(1) | ||
} | ||
|
||
console.log(` jsdom: ${jsdomResult.duration}ms`) | ||
console.log(`happydom: ${happydomResult.duration}ms`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@metascraper-readability/benchmark", | ||
"private": true, | ||
"version": "1.0.0", | ||
"devDependencies": { | ||
"dom-parser": "latest", | ||
"happy-dom": "latest" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters