Skip to content

Commit

Permalink
Merge branch 'main' into add-eslint-comments
Browse files Browse the repository at this point in the history
  • Loading branch information
fb55 authored Dec 26, 2024
2 parents c361baa + c50f1f5 commit 03156ee
Show file tree
Hide file tree
Showing 26 changed files with 4,723 additions and 4,026 deletions.
5 changes: 2 additions & 3 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,10 @@
"overrides": [
{
"files": "*.ts",
"plugins": ["expect-type"],
"extends": [
"plugin:expect-type/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"prettier"
],
"parserOptions": {
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ jobs:
if: matrix.node == env.NODE_COV

- name: Run Coveralls
uses: coverallsapp/github-action@v2.3.3
uses: coverallsapp/github-action@v2.3.4
if: matrix.node == env.NODE_COV
continue-on-error: true
with:
Expand Down
6 changes: 0 additions & 6 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,6 @@ development and support.

<!-- BEGIN SPONSORS: sponsor -->

<a href="https://www.casinoonlineaams.com" target="_blank" rel="noopener noreferrer">
<img height="64px" width="64px" src="https://humble.imgix.net/https%3A%2F%2Fimages.opencollective.com%2Fcasinoonlineaamscom%2Fc59b0fd%2Flogo.png?ixlib=js-3.8.0&w=64&h=64&fit=fillmax&fill=solid&s=7b90355c5df11c3ac489869b01279fee" title="Casinoonlineaams.com" alt="Casinoonlineaams.com"></img>
</a>
<a href="https://www.zenrows.com" target="_blank" rel="noopener noreferrer">
<img height="64px" width="64px" src="https://humble.imgix.net/https%3A%2F%2Fimages.opencollective.com%2Fzenrows%2F3199d4b%2Flogo.png?ixlib=js-3.8.0&w=64&h=64&fit=fillmax&fill=solid&s=8a51972a1004283672506d2e3aedd25b" title="ZenRows" alt="ZenRows"></img>
</a>
<a href="https://slotoking.ua/games/all-slots/" target="_blank" rel="noopener noreferrer">
<img height="64px" width="64px" src="https://humble.imgix.net/https%3A%2F%2Fimages.opencollective.com%2Figrovye-avtomaty-ua%2F96bfde3%2Flogo.png?ixlib=js-3.8.0&w=64&h=64&fit=fillmax&fill=solid&s=07091c88a0b859ecaa81ef10fadf3075" title="Ігрові автомати" alt="Ігрові автомати"></img>
</a>
Expand Down
33 changes: 17 additions & 16 deletions benchmark/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ const benchmarkFilter = filterIndex >= 0 ? process.argv[filterIndex] : '';

const cheerioOnly = process.argv.includes('--cheerio-only');

interface SuiteOptions<T> {
test($: CheerioAPI, data: T): void;
setup($: CheerioAPI): T;
}
type SuiteOptions<T> = T extends void
? {
test(this: void, $: CheerioAPI): void;
setup?: (this: void, $: CheerioAPI) => T;
}
: {
test(this: void, $: CheerioAPI, data: T): void;
setup(this: void, $: CheerioAPI): T;
};

async function benchmark<T>(
async function benchmark<T = void>(
name: string,
fileName: string,
options: SuiteOptions<T>,
Expand All @@ -40,7 +45,7 @@ async function benchmark<T>(

// Add Cheerio test
const $ = load(markup);
const setupData: T = setup($);
const setupData = setup?.($) as T;

bench.add('cheerio', () => {
test($, setupData);
Expand All @@ -52,23 +57,20 @@ async function benchmark<T>(

jQueryScript.runInContext(dom.getInternalVMContext());

const setupData: T = setup(dom.window['$']);
const setupData = setup?.(dom.window['$'] as CheerioAPI) as T;

bench.add('jsdom', () => test(dom.window['$'], setupData));
bench.add('jsdom', () => test(dom.window['$'] as CheerioAPI, setupData));
}

await bench.warmup(); // Make results more reliable, ref: https://github.com/tinylibs/tinybench/pull/50
await bench.run();

console.table(bench.table());
}

await benchmark<void>('Select all', 'jquery.html', {
setup() {},
await benchmark('Select all', 'jquery.html', {
test: ($) => $('*').length,
});
await benchmark<void>('Select some', 'jquery.html', {
setup() {},
await benchmark('Select some', 'jquery.html', {
test: ($) => $('li').length,
});

Expand Down Expand Up @@ -116,7 +118,7 @@ await benchmark<Cheerio<Element>>('manipulation - remove', 'jquery.html', {
},
});

await benchmark<void>('manipulation - replaceWith', 'jquery.html', {
await benchmark('manipulation - replaceWith', 'jquery.html', {
setup($) {
$('body').append('<div id="foo">');
},
Expand Down Expand Up @@ -147,8 +149,7 @@ await benchmark<Cheerio<Element>>('manipulation - html render', 'jquery.html', {

const HTML_INDEPENDENT_MARKUP =
'<div class="foo"><div id="bar">bat<hr>baz</div> </div>'.repeat(6);
await benchmark<void>('manipulation - html independent', 'jquery.html', {
setup() {},
await benchmark('manipulation - html independent', 'jquery.html', {
test: ($) => $(HTML_INDEPENDENT_MARKUP).html(),
});
await benchmark<Cheerio<Element>>('manipulation - text', 'jquery.html', {
Expand Down
Loading

0 comments on commit 03156ee

Please sign in to comment.