Skip to content

Commit a4024b6

Browse files
committed
Add lastIndexOf benchmarks
1 parent 1986af8 commit a4024b6

18 files changed

+1332
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 pkg = require( './../package.json' ).name;
25+
var Float32Array = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg+':lastIndexOf', function benchmark( b ) {
31+
var out;
32+
var arr;
33+
var v;
34+
var i;
35+
36+
arr = new Float32Array( 2 );
37+
38+
// Benchmark worst case scenario...
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
v = (i%127) + 1.0;
42+
out = arr.lastIndexOf( v );
43+
if ( out !== -1 ) {
44+
b.fail( 'should return -1' );
45+
}
46+
}
47+
b.toc();
48+
if ( out !== -1 ) {
49+
b.fail( 'should return -1' );
50+
}
51+
b.pass( 'benchmark finished' );
52+
b.end();
53+
});
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) 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 pkg = require( './../package.json' ).name;
26+
var Float32Array = require( './../lib' );
27+
28+
29+
// FUNCTIONS //
30+
31+
/**
32+
* Creates a benchmark function.
33+
*
34+
* @private
35+
* @param {PositiveInteger} len - array length
36+
* @returns {Function} benchmark function
37+
*/
38+
function createBenchmark( len ) {
39+
var arr = new Float32Array( len );
40+
return benchmark;
41+
42+
/**
43+
* Benchmark function.
44+
*
45+
* @private
46+
* @param {Benchmark} b - benchmark instance
47+
*/
48+
function benchmark( b ) {
49+
var out;
50+
var v;
51+
var i;
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
v = (i%127) + 1.0;
56+
out = arr.lastIndexOf( v );
57+
if ( out !== -1 ) {
58+
b.fail( 'should return -1' );
59+
}
60+
}
61+
b.toc();
62+
if ( out !== -1 ) {
63+
b.fail( 'should return -1' );
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+':lastIndexOf:len='+len, f );
92+
}
93+
}
94+
95+
main();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 pkg = require( './../package.json' ).name;
25+
var Float64Array = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg+':lastIndexOf', function benchmark( b ) {
31+
var out;
32+
var arr;
33+
var v;
34+
var i;
35+
36+
arr = new Float64Array( 2 );
37+
38+
// Benchmark worst case scenario...
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
v = (i%127) + 1.0;
42+
out = arr.lastIndexOf( v );
43+
if ( out !== -1 ) {
44+
b.fail( 'should return -1' );
45+
}
46+
}
47+
b.toc();
48+
if ( out !== -1 ) {
49+
b.fail( 'should return -1' );
50+
}
51+
b.pass( 'benchmark finished' );
52+
b.end();
53+
});
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) 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 pkg = require( './../package.json' ).name;
26+
var Float64Array = require( './../lib' );
27+
28+
29+
// FUNCTIONS //
30+
31+
/**
32+
* Creates a benchmark function.
33+
*
34+
* @private
35+
* @param {PositiveInteger} len - array length
36+
* @returns {Function} benchmark function
37+
*/
38+
function createBenchmark( len ) {
39+
var arr = new Float64Array( len );
40+
return benchmark;
41+
42+
/**
43+
* Benchmark function.
44+
*
45+
* @private
46+
* @param {Benchmark} b - benchmark instance
47+
*/
48+
function benchmark( b ) {
49+
var out;
50+
var v;
51+
var i;
52+
53+
b.tic();
54+
for ( i = 0; i < b.iterations; i++ ) {
55+
v = (i%127) + 1.0;
56+
out = arr.lastIndexOf( v );
57+
if ( out !== -1 ) {
58+
b.fail( 'should return -1' );
59+
}
60+
}
61+
b.toc();
62+
if ( out !== -1 ) {
63+
b.fail( 'should return -1' );
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+':lastIndexOf:len='+len, f );
92+
}
93+
}
94+
95+
main();
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 pkg = require( './../package.json' ).name;
25+
var Int16Array = require( './../lib' );
26+
27+
28+
// MAIN //
29+
30+
bench( pkg+':lastIndexOf', function benchmark( b ) {
31+
var out;
32+
var arr;
33+
var v;
34+
var i;
35+
36+
arr = new Int16Array( 2 );
37+
38+
// Benchmark worst case scenario...
39+
b.tic();
40+
for ( i = 0; i < b.iterations; i++ ) {
41+
v = (i%127) + 1;
42+
out = arr.lastIndexOf( v );
43+
if ( out !== -1 ) {
44+
b.fail( 'should return -1' );
45+
}
46+
}
47+
b.toc();
48+
if ( out !== -1 ) {
49+
b.fail( 'should return -1' );
50+
}
51+
b.pass( 'benchmark finished' );
52+
b.end();
53+
});

0 commit comments

Comments
 (0)