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: split `Buffer.byteLength` benchmark · nodejs/node@d4af671

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • benchmark/buffers
    • buffer-bytelength-buffer.js
    • buffer-bytelength-string.js
    • buffer-bytelength.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎benchmark/buffers/buffer-bytelength-buffer.js‎

Copy file name to clipboard
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
const bench = common.createBenchmark(main, {
5+
len: [2, 16, 256], // x16
6+
n: [4e6],
7+
});
8+
9+
function main({ n, len }) {
10+
const data = Buffer.alloc(len * 16, 'a');
11+
const expected = Buffer.byteLength(data, 'buffer');
12+
let changed = false;
13+
bench.start();
14+
for (let i = 0; i < n; i++) {
15+
const actual = Buffer.byteLength(data, 'buffer');
16+
if (expected !== actual) { changed = true; }
17+
}
18+
bench.end(n);
19+
if (changed) {
20+
throw new Error('Result changed during iteration');
21+
}
22+
}
Collapse file

‎benchmark/buffers/buffer-bytelength-string.js‎

Copy file name to clipboard
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
const common = require('../common');
3+
4+
const bench = common.createBenchmark(main, {
5+
type: ['one_byte', 'two_bytes', 'three_bytes', 'four_bytes'],
6+
encoding: ['utf8', 'base64'],
7+
repeat: [1, 2, 16, 256], // x16
8+
n: [4e6],
9+
});
10+
11+
// 16 chars each
12+
const chars = {
13+
one_byte: 'hello brendan!!!',
14+
two_bytes: 'ΰαβγδεζηθικλμνξο',
15+
three_bytes: '挰挱挲挳挴挵挶挷挸挹挺挻挼挽挾挿',
16+
four_bytes: '𠜎𠜱𠝹𠱓𠱸𠲖𠳏𠳕𠴕𠵼𠵿𠸎𠸏𠹷𠺝𠺢',
17+
};
18+
19+
function getInput(type, repeat, encoding) {
20+
const original = (repeat === 1) ? chars[type] : chars[type].repeat(repeat);
21+
if (encoding === 'base64') {
22+
Buffer.from(original, 'utf8').toString('base64');
23+
}
24+
return original;
25+
}
26+
27+
function main({ n, repeat, encoding, type }) {
28+
const data = getInput(type, repeat, encoding);
29+
const expected = Buffer.byteLength(data, encoding);
30+
let changed = false;
31+
bench.start();
32+
for (let i = 0; i < n; i++) {
33+
const actual = Buffer.byteLength(data, encoding);
34+
if (expected !== actual) { changed = true; }
35+
}
36+
bench.end(n);
37+
if (changed) {
38+
throw new Error('Result changed during iteration');
39+
}
40+
}
Collapse file

‎benchmark/buffers/buffer-bytelength.js‎

Copy file name to clipboardExpand all lines: benchmark/buffers/buffer-bytelength.js
-49Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
0 (0)
You are visitor 01402503 — 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.