Skip to content

Commit d2f1311

Browse files
authored
Update benchmark.ndarray.js
Signed-off-by: Kaushikgtm <[email protected]>
1 parent 752c833 commit d2f1311

File tree

1 file changed

+12
-13
lines changed

1 file changed

+12
-13
lines changed

lib/node_modules/@stdlib/stats/base/nanrange-by/benchmark/benchmark.ndarray.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* @license Apache-2.0
33
*
4-
* Copyright (c) 2020 The Stdlib Authors.
4+
* Copyright (c) 2025 The Stdlib Authors.
55
*
66
* Licensed under the Apache License, Version 2.0 (the "License");
77
* you may not use this file except in compliance with the License.
@@ -21,7 +21,9 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randu = require( '@stdlib/random/base/randu' );
24+
var uniform = require( '@stdlib/random/base/uniform' );
25+
var filledarrayBy = require( '@stdlib/array/filled-by' );
26+
var bernoulli = require( '@stdlib/random/base/bernoulli' );
2527
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2628
var pow = require( '@stdlib/math/base/special/pow' );
2729
var pkg = require( './../package.json' ).name;
@@ -37,6 +39,13 @@ var nanrangeBy = require( './../lib/ndarray.js' );
3739
* @param {number} value - array element
3840
* @returns {number} accessed value
3941
*/
42+
function rand() {
43+
if ( bernoulli( 0.8 ) < 1 ) {
44+
return NaN;
45+
}
46+
return uniform( -50.0, 50.0 );
47+
}
48+
4049
function accessor( value ) {
4150
return value * 2.0;
4251
}
@@ -49,17 +58,7 @@ function accessor( value ) {
4958
* @returns {Function} benchmark function
5059
*/
5160
function createBenchmark( len ) {
52-
var x;
53-
var i;
54-
55-
x = [];
56-
for ( i = 0; i < len; i++ ) {
57-
if ( randu() < 0.2 ) {
58-
x.push( NaN );
59-
} else {
60-
x.push( ( randu()*20.0 ) - 10.0 );
61-
}
62-
}
61+
var x = filledarrayBy( len, "float64", rand );
6362
return benchmark;
6463

6564
function benchmark( b ) {

0 commit comments

Comments
 (0)