GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — benchmark: add URLSearchParams iterator consumers benchmark · nodejs/node@81d2321

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/url
    • url-searchparams-iterator-consumers.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/url/url-searchparams-iterator-consumers.js‎

Copy file name to clipboard
+53Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const assert = require('assert');
4+
5+
// Consumes a URLSearchParams iterator with builtins that have fast paths for
6+
// iterator result objects (Array.from, Map constructor, Object.fromEntries),
7+
// plus for-of for comparison.
8+
const bench = common.createBenchmark(main, {
9+
method: ['Array.from', 'Map', 'Object.fromEntries', 'for-of'],
10+
n: [1e6],
11+
});
12+
13+
const str = 'one=single&two=first&three=first&two=2nd&three=2nd&three=3rd';
14+
15+
function main({ method, n }) {
16+
const params = new URLSearchParams(str);
17+
let noDead;
18+
19+
switch (method) {
20+
case 'Array.from':
21+
bench.start();
22+
for (let i = 0; i < n; i += 1)
23+
noDead = Array.from(params);
24+
bench.end(n);
25+
assert.strictEqual(noDead.length, 6);
26+
break;
27+
case 'Map':
28+
bench.start();
29+
for (let i = 0; i < n; i += 1)
30+
noDead = new Map(params);
31+
bench.end(n);
32+
assert.strictEqual(noDead.size, 3);
33+
break;
34+
case 'Object.fromEntries':
35+
bench.start();
36+
for (let i = 0; i < n; i += 1)
37+
noDead = Object.fromEntries(params);
38+
bench.end(n);
39+
assert.strictEqual(noDead.three, '3rd');
40+
break;
41+
case 'for-of':
42+
bench.start();
43+
for (let i = 0; i < n; i += 1) {
44+
for (const pair of params)
45+
noDead = pair;
46+
}
47+
bench.end(n);
48+
assert.strictEqual(noDead[1], '3rd');
49+
break;
50+
default:
51+
throw new Error(`Unknown method ${method}`);
52+
}
53+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.