Skip to content

Commit 9c7b8ba

Browse files
committed
fix: replace new Array() with array literals in ztest benchmark
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: passed - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: na - task: lint_license_headers status: passed ---
1 parent a47cd2a commit 9c7b8ba

1 file changed

Lines changed: 40 additions & 21 deletions

File tree

lib/node_modules/@stdlib/stats/ztest/benchmark/benchmark.js

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,30 @@ var randu = require( '@stdlib/random/base/randu' );
2525
var isObject = require( '@stdlib/assert/is-object' );
2626
var isString = require( '@stdlib/assert/is-string' ).isPrimitive;
2727
var stdev = require( '@stdlib/stats/base/dists/uniform/stdev' );
28+
var format = require( '@stdlib/string/format' );
2829
var pkg = require( './../package.json' ).name;
2930
var ztest = require( './../lib' );
3031

3132

3233
// MAIN //
3334

34-
bench( pkg, function benchmark( b ) {
35+
bench( pkg, benchmark );
36+
37+
/**
38+
* Benchmark function.
39+
*
40+
* @private
41+
* @param {Benchmark} b - benchmark instance
42+
*/
43+
function benchmark( b ) {
3544
var result;
3645
var sigma;
37-
var len;
3846
var x;
3947
var i;
4048

41-
x = new Array( 100 );
42-
len = x.length;
43-
for ( i = 0; i < len; i++ ) {
44-
x[ i ] = randu()*50.0;
49+
x = [];
50+
for ( i = 0; i < 100; i++ ) {
51+
x.push( randu()*50.0 );
4552
}
4653
sigma = stdev( 0.0, 50.0 );
4754

@@ -59,20 +66,26 @@ bench( pkg, function benchmark( b ) {
5966
}
6067
b.pass( 'benchmark finished' );
6168
b.end();
62-
});
69+
}
70+
71+
bench( format( '%s::one-sided', pkg ), benchmark2 );
6372

64-
bench( pkg+'::one-sided', function benchmark( b ) {
73+
/**
74+
* Benchmark function.
75+
*
76+
* @private
77+
* @param {Benchmark} b - benchmark instance
78+
*/
79+
function benchmark2( b ) {
6580
var result;
6681
var sigma;
6782
var opts;
68-
var len;
6983
var x;
7084
var i;
7185

72-
x = new Array( 100 );
73-
len = x.length;
74-
for ( i = 0; i < len; i++ ) {
75-
x[ i ] = randu()*50.0;
86+
x = [];
87+
for ( i = 0; i < 100; i++ ) {
88+
x.push( randu()*50.0 );
7689
}
7790
opts = {
7891
'alternative': 'less'
@@ -93,21 +106,27 @@ bench( pkg+'::one-sided', function benchmark( b ) {
93106
}
94107
b.pass( 'benchmark finished' );
95108
b.end();
96-
});
109+
}
110+
111+
bench( format( '%s:print', pkg ), benchmark3 );
97112

98-
bench( pkg+':print', function benchmark( b ) {
113+
/**
114+
* Benchmark function.
115+
*
116+
* @private
117+
* @param {Benchmark} b - benchmark instance
118+
*/
119+
function benchmark3( b ) {
99120
var digits;
100121
var result;
101122
var output;
102123
var sigma;
103-
var len;
104124
var x;
105125
var i;
106126

107-
x = new Array( 100 );
108-
len = x.length;
109-
for ( i = 0; i < len; i++ ) {
110-
x[ i ] = randu()*50.0;
127+
x = [];
128+
for ( i = 0; i < 100; i++ ) {
129+
x.push( randu()*50.0 );
111130
}
112131
sigma = stdev( 0.0, 50.0 );
113132
result = ztest( x, sigma );
@@ -128,4 +147,4 @@ bench( pkg+':print', function benchmark( b ) {
128147
}
129148
b.pass( 'benchmark finished' );
130149
b.end();
131-
});
150+
}

0 commit comments

Comments
 (0)