Skip to content

Commit a3a04e3

Browse files
committed
feat: add array/fixed-endian-factory
1 parent d8a7b13 commit a3a04e3

18 files changed

+3159
-0
lines changed

lib/node_modules/@stdlib/array/fixed-endian-factory/README.md

+503
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,311 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2024 The Stdlib Authors.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
'use strict';
20+
21+
// MODULES //
22+
23+
var bench = require( '@stdlib/bench' );
24+
var Float64Array = require( '@stdlib/array/float64' );
25+
var ITERATOR_SYMBOL = require( '@stdlib/symbol/iterator' );
26+
var pkg = require( './../package.json' ).name;
27+
var factory = require( './../lib' );
28+
29+
30+
// VARIABLES //
31+
32+
var opts = {
33+
'skip': ( ITERATOR_SYMBOL === null )
34+
};
35+
var Float64ArrayFE = factory( 'float64' );
36+
37+
38+
// MAIN //
39+
40+
bench( pkg+'::typed_array:from', function benchmark( b ) {
41+
var buf;
42+
var arr;
43+
var i;
44+
45+
buf = new Float64Array( 0 );
46+
47+
b.tic();
48+
for ( i = 0; i < b.iterations; i++ ) {
49+
arr = Float64ArrayFE.from( 'little-endian', buf );
50+
if ( arr.length !== 0 ) {
51+
b.fail( 'should have length 0' );
52+
}
53+
}
54+
b.toc();
55+
if ( !(arr instanceof Float64ArrayFE) ) {
56+
b.fail( 'should return an instance' );
57+
}
58+
b.pass( 'benchmark finished' );
59+
b.end();
60+
});
61+
62+
bench( pkg+'::typed_array:from:len=5', function benchmark( b ) {
63+
var buf;
64+
var arr;
65+
var i;
66+
67+
buf = new Float64Array( 5 );
68+
69+
b.tic();
70+
for ( i = 0; i < b.iterations; i++ ) {
71+
arr = Float64ArrayFE.from( 'little-endian', buf );
72+
if ( arr.length !== 5 ) {
73+
b.fail( 'should have length 5' );
74+
}
75+
}
76+
b.toc();
77+
if ( !(arr instanceof Float64ArrayFE) ) {
78+
b.fail( 'should return an instance' );
79+
}
80+
b.pass( 'benchmark finished' );
81+
b.end();
82+
});
83+
84+
bench( pkg+'::typed_array,clbk:from:len=5', function benchmark( b ) {
85+
var buf;
86+
var arr;
87+
var i;
88+
89+
buf = new Float64Array( 5 );
90+
91+
b.tic();
92+
for ( i = 0; i < b.iterations; i++ ) {
93+
arr = Float64ArrayFE.from( 'little-endian', buf, clbk );
94+
if ( arr.length !== 5 ) {
95+
b.fail( 'should have length 5' );
96+
}
97+
}
98+
b.toc();
99+
if ( !(arr instanceof Float64ArrayFE) ) {
100+
b.fail( 'should return an instance' );
101+
}
102+
b.pass( 'benchmark finished' );
103+
b.end();
104+
105+
function clbk( v ) {
106+
return v * 2.0;
107+
}
108+
});
109+
110+
bench( pkg+'::array:from', function benchmark( b ) {
111+
var buf;
112+
var arr;
113+
var i;
114+
115+
buf = [];
116+
117+
b.tic();
118+
for ( i = 0; i < b.iterations; i++ ) {
119+
arr = Float64ArrayFE.from( 'little-endian', buf );
120+
if ( arr.length !== 0 ) {
121+
b.fail( 'should have length 0' );
122+
}
123+
}
124+
b.toc();
125+
if ( !(arr instanceof Float64ArrayFE) ) {
126+
b.fail( 'should return an instance' );
127+
}
128+
b.pass( 'benchmark finished' );
129+
b.end();
130+
});
131+
132+
bench( pkg+'::array:from:len=5', function benchmark( b ) {
133+
var buf;
134+
var arr;
135+
var i;
136+
137+
buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ];
138+
139+
b.tic();
140+
for ( i = 0; i < b.iterations; i++ ) {
141+
arr = Float64ArrayFE.from( 'little-endian', buf );
142+
if ( arr.length !== 5 ) {
143+
b.fail( 'should have length 5' );
144+
}
145+
}
146+
b.toc();
147+
if ( !(arr instanceof Float64ArrayFE) ) {
148+
b.fail( 'should return an instance' );
149+
}
150+
b.pass( 'benchmark finished' );
151+
b.end();
152+
});
153+
154+
bench( pkg+'::array,clbk:from:len=5', function benchmark( b ) {
155+
var buf;
156+
var arr;
157+
var i;
158+
159+
buf = [ 1.0, 1.0, 1.0, 1.0, 1.0 ];
160+
161+
b.tic();
162+
for ( i = 0; i < b.iterations; i++ ) {
163+
arr = Float64ArrayFE.from( 'little-endian', buf, clbk );
164+
if ( arr.length !== 5 ) {
165+
b.fail( 'should have length 5' );
166+
}
167+
}
168+
b.toc();
169+
if ( !(arr instanceof Float64ArrayFE) ) {
170+
b.fail( 'should return an instance' );
171+
}
172+
b.pass( 'benchmark finished' );
173+
b.end();
174+
175+
function clbk( v ) {
176+
return v * 2.0;
177+
}
178+
});
179+
180+
bench( pkg+'::iterable:from', opts, function benchmark( b ) {
181+
var arr;
182+
var i;
183+
184+
b.tic();
185+
for ( i = 0; i < b.iterations; i++ ) {
186+
arr = Float64ArrayFE.from( 'little-endian', createIterable() );
187+
if ( arr.length !== 0 ) {
188+
b.fail( 'should have length 0' );
189+
}
190+
}
191+
b.toc();
192+
if ( !(arr instanceof Float64ArrayFE) ) {
193+
b.fail( 'should return an instance' );
194+
}
195+
b.pass( 'benchmark finished' );
196+
b.end();
197+
198+
function createIterable() {
199+
var out = {};
200+
out[ ITERATOR_SYMBOL ] = iterator;
201+
return out;
202+
203+
function iterator() {
204+
return {
205+
'next': next
206+
};
207+
}
208+
209+
function next() {
210+
return {
211+
'done': true
212+
};
213+
}
214+
}
215+
});
216+
217+
bench( pkg+'::iterable:from:len=5', opts, function benchmark( b ) {
218+
var arr;
219+
var i;
220+
221+
b.tic();
222+
for ( i = 0; i < b.iterations; i++ ) {
223+
arr = Float64ArrayFE.from( 'little-endian', createIterable() );
224+
if ( arr.length !== 5 ) {
225+
b.fail( 'should have length 5' );
226+
}
227+
}
228+
b.toc();
229+
if ( !(arr instanceof Float64ArrayFE) ) {
230+
b.fail( 'should return an instance' );
231+
}
232+
b.pass( 'benchmark finished' );
233+
b.end();
234+
235+
function createIterable() {
236+
var out = {};
237+
out[ ITERATOR_SYMBOL ] = iterator;
238+
return out;
239+
240+
function iterator() {
241+
var it = {
242+
'next': next,
243+
'i': 0,
244+
'N': 5
245+
};
246+
return it;
247+
248+
function next() {
249+
it.i += 1;
250+
if ( it.i <= it.N ) {
251+
return {
252+
'value': 1.0
253+
};
254+
}
255+
return {
256+
'done': true
257+
};
258+
}
259+
}
260+
}
261+
});
262+
263+
bench( pkg+'::iterable,clbk:from:len=5', opts, function benchmark( b ) {
264+
var arr;
265+
var i;
266+
267+
b.tic();
268+
for ( i = 0; i < b.iterations; i++ ) {
269+
arr = Float64ArrayFE.from( 'little-endian', createIterable(), clbk );
270+
if ( arr.length !== 5 ) {
271+
b.fail( 'should have length 5' );
272+
}
273+
}
274+
b.toc();
275+
if ( !(arr instanceof Float64ArrayFE) ) {
276+
b.fail( 'should return an instance' );
277+
}
278+
b.pass( 'benchmark finished' );
279+
b.end();
280+
281+
function createIterable() {
282+
var out = {};
283+
out[ ITERATOR_SYMBOL ] = iterator;
284+
return out;
285+
286+
function iterator() {
287+
var it = {
288+
'next': next,
289+
'i': 0,
290+
'N': 5
291+
};
292+
return it;
293+
294+
function next() {
295+
it.i += 1;
296+
if ( it.i <= it.N ) {
297+
return {
298+
'value': 1.0
299+
};
300+
}
301+
return {
302+
'done': true
303+
};
304+
}
305+
}
306+
}
307+
308+
function clbk( v ) {
309+
return v * 2.0;
310+
}
311+
});

0 commit comments

Comments
 (0)