Skip to content

Commit 7900a88

Browse files
committed
Add every benchmarks
1 parent ccc160f commit 7900a88

File tree

18 files changed

+1674
-0
lines changed

18 files changed

+1674
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var Float32Array = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':every', function benchmark( b ) {
32+
var bool;
33+
var arr;
34+
var i;
35+
36+
arr = new Float32Array( 2 );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
bool = arr.every( predicate );
41+
if ( typeof bool !== 'boolean' ) {
42+
b.fail( 'should return a boolean' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBoolean( bool ) ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
52+
function predicate( v ) {
53+
return v >= 0.0;
54+
}
55+
});
56+
57+
bench( pkg+'::this_context:every', function benchmark( b ) {
58+
var bool;
59+
var arr;
60+
var i;
61+
62+
arr = new Float32Array( 2 );
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
bool = arr.every( predicate, {} );
67+
if ( typeof bool !== 'boolean' ) {
68+
b.fail( 'should return a boolean' );
69+
}
70+
}
71+
b.toc();
72+
if ( !isBoolean( bool ) ) {
73+
b.fail( 'should return a boolean' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
78+
function predicate( v ) {
79+
return v >= 0.0;
80+
}
81+
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' );
25+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var pkg = require( './../package.json' ).name;
27+
var Float32Array = require( './../lib' );
28+
29+
30+
// FUNCTIONS //
31+
32+
/**
33+
* Returns a boolean indicating whether an array element passes a test.
34+
*
35+
* @private
36+
* @param {*} value - value to test
37+
* @returns {boolean} boolean indicating whether an array element passes a test
38+
*/
39+
function predicate( value ) {
40+
return value >= 0.0;
41+
}
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} len - array length
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( len ) {
51+
var arr = new Float32Array( len );
52+
return benchmark;
53+
54+
/**
55+
* Benchmark function.
56+
*
57+
* @private
58+
* @param {Benchmark} b - benchmark instance
59+
*/
60+
function benchmark( b ) {
61+
var bool;
62+
var i;
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
bool = arr.every( predicate );
67+
if ( typeof bool !== 'boolean' ) {
68+
b.fail( 'should return a boolean' );
69+
}
70+
}
71+
b.toc();
72+
if ( !isBoolean( bool ) ) {
73+
b.fail( 'should return a boolean' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var len;
90+
var min;
91+
var max;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 6; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
len = pow( 10, i );
100+
f = createBenchmark( len );
101+
bench( pkg+':every:len='+len, f );
102+
}
103+
}
104+
105+
main();
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
25+
var pkg = require( './../package.json' ).name;
26+
var Float64Array = require( './../lib' );
27+
28+
29+
// MAIN //
30+
31+
bench( pkg+':every', function benchmark( b ) {
32+
var bool;
33+
var arr;
34+
var i;
35+
36+
arr = new Float64Array( 2 );
37+
38+
b.tic();
39+
for ( i = 0; i < b.iterations; i++ ) {
40+
bool = arr.every( predicate );
41+
if ( typeof bool !== 'boolean' ) {
42+
b.fail( 'should return a boolean' );
43+
}
44+
}
45+
b.toc();
46+
if ( !isBoolean( bool ) ) {
47+
b.fail( 'should return a boolean' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
52+
function predicate( v ) {
53+
return v >= 0.0;
54+
}
55+
});
56+
57+
bench( pkg+'::this_context:every', function benchmark( b ) {
58+
var bool;
59+
var arr;
60+
var i;
61+
62+
arr = new Float64Array( 2 );
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
bool = arr.every( predicate, {} );
67+
if ( typeof bool !== 'boolean' ) {
68+
b.fail( 'should return a boolean' );
69+
}
70+
}
71+
b.toc();
72+
if ( !isBoolean( bool ) ) {
73+
b.fail( 'should return a boolean' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
78+
function predicate( v ) {
79+
return v >= 0.0;
80+
}
81+
});
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2018 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 pow = require( '@stdlib/math/base/special/pow' );
25+
var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive;
26+
var pkg = require( './../package.json' ).name;
27+
var Float64Array = require( './../lib' );
28+
29+
30+
// FUNCTIONS //
31+
32+
/**
33+
* Returns a boolean indicating whether an array element passes a test.
34+
*
35+
* @private
36+
* @param {*} value - value to test
37+
* @returns {boolean} boolean indicating whether an array element passes a test
38+
*/
39+
function predicate( value ) {
40+
return value >= 0.0;
41+
}
42+
43+
/**
44+
* Creates a benchmark function.
45+
*
46+
* @private
47+
* @param {PositiveInteger} len - array length
48+
* @returns {Function} benchmark function
49+
*/
50+
function createBenchmark( len ) {
51+
var arr = new Float64Array( len );
52+
return benchmark;
53+
54+
/**
55+
* Benchmark function.
56+
*
57+
* @private
58+
* @param {Benchmark} b - benchmark instance
59+
*/
60+
function benchmark( b ) {
61+
var bool;
62+
var i;
63+
64+
b.tic();
65+
for ( i = 0; i < b.iterations; i++ ) {
66+
bool = arr.every( predicate );
67+
if ( typeof bool !== 'boolean' ) {
68+
b.fail( 'should return a boolean' );
69+
}
70+
}
71+
b.toc();
72+
if ( !isBoolean( bool ) ) {
73+
b.fail( 'should return a boolean' );
74+
}
75+
b.pass( 'benchmark finished' );
76+
b.end();
77+
}
78+
}
79+
80+
81+
// MAIN //
82+
83+
/**
84+
* Main execution sequence.
85+
*
86+
* @private
87+
*/
88+
function main() {
89+
var len;
90+
var min;
91+
var max;
92+
var f;
93+
var i;
94+
95+
min = 1; // 10^min
96+
max = 6; // 10^max
97+
98+
for ( i = min; i <= max; i++ ) {
99+
len = pow( 10, i );
100+
f = createBenchmark( len );
101+
bench( pkg+':every:len='+len, f );
102+
}
103+
}
104+
105+
main();

0 commit comments

Comments
 (0)