@@ -2,10 +2,12 @@ import { base64 } from 'rfc4648';
2
2
import { PerformanceBase } from './base.js' ;
3
3
4
4
const test = new PerformanceBase ( 1e6 ) ;
5
+ const testForLong = new PerformanceBase ( 1e3 ) ;
5
6
6
7
// Hello world
7
8
const b64Str = 'SGVsbG8gd29ybGQ=' ;
8
9
const b64Arr = [ 72 , 101 , 108 , 108 , 111 , 32 , 119 , 111 , 114 , 108 , 100 ] ;
10
+ const tooLongUint8Array = new Uint8Array ( 1e6 ) ;
9
11
10
12
{
11
13
if ( base64 . parse ( b64Str ) . join ( ',' ) !== b64Arr . join ( ',' ) ) {
@@ -57,30 +59,58 @@ const b64Arr = [72, 101, 108, 108, 111, 32, 119, 111, 114, 108, 100];
57
59
}
58
60
return true ;
59
61
}
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 ( ) ;
64
73
}
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 ( ) ;
68
85
}
69
- test . end ( ) ;
70
86
}
71
87
{
72
88
const equal = ( a , b ) => {
73
89
if ( a . length !== b . length ) return false ;
74
90
return a . every ( ( v , i ) => v === b [ i ] ) ;
75
91
}
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 ( ) ;
80
103
}
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 ( ) ;
84
115
}
85
- test . end ( ) ;
86
116
}
0 commit comments