Skip to content

Commit 1a73971

Browse files
committed
tooLongUint8Array
1 parent 4a1a327 commit 1a73971

File tree

1 file changed

+46
-16
lines changed

1 file changed

+46
-16
lines changed

test/performance/base64.js

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@ import { base64 } from 'rfc4648';
22
import { PerformanceBase } from './base.js';
33

44
const test = new PerformanceBase(1e6);
5+
const testForLong = new PerformanceBase(1e3);
56

67
// Hello world
78
const b64Str = 'SGVsbG8gd29ybGQ=';
89
const b64Arr = [72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100];
10+
const tooLongUint8Array = new Uint8Array(1e6);
911

1012
{
1113
if (base64.parse(b64Str).join(',') !== b64Arr.join(',')) {
@@ -57,30 +59,58 @@ const b64Arr = [72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100];
5759
}
5860
return true;
5961
}
60-
const arrA = new Uint8Array(b64Arr);
61-
const arrB = new Uint8Array(b64Arr);
62-
if (arrA === arrB) {
63-
throw new Error('comparing same object');
62+
{
63+
const arrA = new Uint8Array(b64Arr);
64+
const arrB = new Uint8Array(b64Arr);
65+
if (arrA === arrB) {
66+
throw new Error('comparing same object');
67+
}
68+
test.start(`uint8array equality for of (short)`);
69+
for (let i = 0; i < test.TRYES; i++) {
70+
if (!equal(arrA, arrB)) throw new Error('not equal');
71+
}
72+
test.end();
6473
}
65-
test.start(`uint8array equality for of`);
66-
for (let i = 0; i < test.TRYES; i++) {
67-
if (!equal(arrA, arrB)) throw new Error('not equal');
74+
{
75+
const tooLongArrA = new Uint8Array(tooLongUint8Array);
76+
const tooLongArrB = new Uint8Array(tooLongUint8Array);
77+
if (tooLongArrA === tooLongArrB) {
78+
throw new Error('comparing same object');
79+
}
80+
testForLong.start(`uint8array equality for of (long)`);
81+
for (let i = 0; i < testForLong.TRYES; i++) {
82+
if (!equal(tooLongArrA, tooLongArrB)) throw new Error('not equal');
83+
}
84+
testForLong.end();
6885
}
69-
test.end();
7086
}
7187
{
7288
const equal = (a, b) => {
7389
if (a.length !== b.length) return false;
7490
return a.every((v, i) => v === b[i]);
7591
}
76-
const arrA = new Uint8Array(b64Arr);
77-
const arrB = new Uint8Array(b64Arr);
78-
if (arrA === arrB) {
79-
throw new Error('comparing same object');
92+
{
93+
const arrA = new Uint8Array(b64Arr);
94+
const arrB = new Uint8Array(b64Arr);
95+
if (arrA === arrB) {
96+
throw new Error('comparing same object');
97+
}
98+
test.start(`uint8array equality arr.every (short)`);
99+
for (let i = 0; i < test.TRYES; i++) {
100+
if (!equal(arrA, arrB)) throw new Error('not equal');
101+
}
102+
test.end();
80103
}
81-
test.start(`uint8array equality arr.every`);
82-
for (let i = 0; i < test.TRYES; i++) {
83-
if (!equal(arrA, arrB)) throw new Error('not equal');
104+
{
105+
const tooLongArrA = new Uint8Array(tooLongUint8Array);
106+
const tooLongArrB = new Uint8Array(tooLongUint8Array);
107+
if (tooLongArrA === tooLongArrB) {
108+
throw new Error('comparing same object');
109+
}
110+
testForLong.start(`uint8array equality arr.every (long)`);
111+
for (let i = 0; i < testForLong.TRYES; i++) {
112+
if (!equal(tooLongArrA, tooLongArrB)) throw new Error('not equal');
113+
}
114+
testForLong.end();
84115
}
85-
test.end();
86116
}

0 commit comments

Comments
 (0)