Skip to content

Commit 584fa55

Browse files
committed
Add benchmarks
1 parent 4845365 commit 584fa55

17 files changed

+1679
-0
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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 isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
26+
var Complex128Array = require( '@stdlib/array/complex128' );
27+
var Complex128 = require( '@stdlib/complex/float64' );
28+
var pkg = require( './../package.json' ).name;
29+
var linspace = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var out = new Complex128Array( len );
43+
return benchmark;
44+
45+
/**
46+
* Benchmark function.
47+
*
48+
* @private
49+
* @param {Benchmark} b - benchmark instance
50+
*/
51+
function benchmark( b ) {
52+
var x1;
53+
var x2;
54+
var v;
55+
var i;
56+
57+
x1 = new Complex128( 0.0, 0.0 );
58+
x2 = new Complex128( 100.0, 10.0 );
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
v = linspace.assign( x1, x2, out );
63+
if ( typeof v !== 'object' ) {
64+
b.fail( 'should return an array-like object' );
65+
}
66+
}
67+
b.toc();
68+
if ( !isArrayLikeObject( v ) ) {
69+
b.fail( 'should return an array-like object' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
}
74+
}
75+
76+
77+
// MAIN //
78+
79+
/**
80+
* Main execution sequence.
81+
*
82+
* @private
83+
*/
84+
function main() {
85+
var len;
86+
var min;
87+
var max;
88+
var f;
89+
var i;
90+
91+
min = 1; // 10^min
92+
max = 6; // 10^max
93+
94+
for ( i = min; i <= max; i++ ) {
95+
len = pow( 10, i );
96+
f = createBenchmark( len );
97+
bench( pkg+'::complex:assign:dtype=complex128,len='+len, f );
98+
}
99+
}
100+
101+
main();
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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 isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
26+
var Complex128Array = require( '@stdlib/array/complex128' );
27+
var pkg = require( './../package.json' ).name;
28+
var linspace = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var out = new Complex128Array( len );
42+
return benchmark;
43+
44+
/**
45+
* Benchmark function.
46+
*
47+
* @private
48+
* @param {Benchmark} b - benchmark instance
49+
*/
50+
function benchmark( b ) {
51+
var v;
52+
var i;
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
v = linspace.assign( 0.0, 100.0, out );
57+
if ( typeof v !== 'object' ) {
58+
b.fail( 'should return an array-like object' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isArrayLikeObject( v ) ) {
63+
b.fail( 'should return an array-like object' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var len;
80+
var min;
81+
var max;
82+
var f;
83+
var i;
84+
85+
min = 1; // 10^min
86+
max = 6; // 10^max
87+
88+
for ( i = min; i <= max; i++ ) {
89+
len = pow( 10, i );
90+
f = createBenchmark( len );
91+
bench( pkg+'::real:assign:dtype=complex128,len='+len, f );
92+
}
93+
}
94+
95+
main();
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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 isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
26+
var Complex64Array = require( '@stdlib/array/complex64' );
27+
var Complex64 = require( '@stdlib/complex/float32' );
28+
var pkg = require( './../package.json' ).name;
29+
var linspace = require( './../lib' );
30+
31+
32+
// FUNCTIONS //
33+
34+
/**
35+
* Creates a benchmark function.
36+
*
37+
* @private
38+
* @param {PositiveInteger} len - array length
39+
* @returns {Function} benchmark function
40+
*/
41+
function createBenchmark( len ) {
42+
var out = new Complex64Array( len );
43+
return benchmark;
44+
45+
/**
46+
* Benchmark function.
47+
*
48+
* @private
49+
* @param {Benchmark} b - benchmark instance
50+
*/
51+
function benchmark( b ) {
52+
var x1;
53+
var x2;
54+
var v;
55+
var i;
56+
57+
x1 = new Complex64( 0.0, 0.0 );
58+
x2 = new Complex64( 100.0, 10.0 );
59+
60+
b.tic();
61+
for ( i = 0; i < b.iterations; i++ ) {
62+
v = linspace.assign( x1, x2, out );
63+
if ( typeof v !== 'object' ) {
64+
b.fail( 'should return an array-like object' );
65+
}
66+
}
67+
b.toc();
68+
if ( !isArrayLikeObject( v ) ) {
69+
b.fail( 'should return an array-like object' );
70+
}
71+
b.pass( 'benchmark finished' );
72+
b.end();
73+
}
74+
}
75+
76+
77+
// MAIN //
78+
79+
/**
80+
* Main execution sequence.
81+
*
82+
* @private
83+
*/
84+
function main() {
85+
var len;
86+
var min;
87+
var max;
88+
var f;
89+
var i;
90+
91+
min = 1; // 10^min
92+
max = 6; // 10^max
93+
94+
for ( i = min; i <= max; i++ ) {
95+
len = pow( 10, i );
96+
f = createBenchmark( len );
97+
bench( pkg+'::complex:assign:dtype=complex64,len='+len, f );
98+
}
99+
}
100+
101+
main();
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2022 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 isArrayLikeObject = require( '@stdlib/assert/is-array-like-object' );
26+
var Complex64Array = require( '@stdlib/array/complex64' );
27+
var pkg = require( './../package.json' ).name;
28+
var linspace = require( './../lib' );
29+
30+
31+
// FUNCTIONS //
32+
33+
/**
34+
* Creates a benchmark function.
35+
*
36+
* @private
37+
* @param {PositiveInteger} len - array length
38+
* @returns {Function} benchmark function
39+
*/
40+
function createBenchmark( len ) {
41+
var out = new Complex64Array( len );
42+
return benchmark;
43+
44+
/**
45+
* Benchmark function.
46+
*
47+
* @private
48+
* @param {Benchmark} b - benchmark instance
49+
*/
50+
function benchmark( b ) {
51+
var v;
52+
var i;
53+
54+
b.tic();
55+
for ( i = 0; i < b.iterations; i++ ) {
56+
v = linspace.assign( 0.0, 100.0, out );
57+
if ( typeof v !== 'object' ) {
58+
b.fail( 'should return an array-like object' );
59+
}
60+
}
61+
b.toc();
62+
if ( !isArrayLikeObject( v ) ) {
63+
b.fail( 'should return an array-like object' );
64+
}
65+
b.pass( 'benchmark finished' );
66+
b.end();
67+
}
68+
}
69+
70+
71+
// MAIN //
72+
73+
/**
74+
* Main execution sequence.
75+
*
76+
* @private
77+
*/
78+
function main() {
79+
var len;
80+
var min;
81+
var max;
82+
var f;
83+
var i;
84+
85+
min = 1; // 10^min
86+
max = 6; // 10^max
87+
88+
for ( i = min; i <= max; i++ ) {
89+
len = pow( 10, i );
90+
f = createBenchmark( len );
91+
bench( pkg+'::real:assign:dtype=complex64,len='+len, f );
92+
}
93+
}
94+
95+
main();

0 commit comments

Comments
 (0)