Skip to content

Commit 44d2a1b

Browse files
committed
Add toLocaleString benchmarks
1 parent 9743c01 commit 44d2a1b

18 files changed

+1305
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+':toLocaleString', function benchmark( b ) {
31+
var out;
32+
var arr;
33+
var i;
34+
35+
arr = new Float32Array( 2 );
36+
37+
b.tic();
38+
for ( i = 0; i < b.iterations; i++ ) {
39+
arr[ 0 ] = i;
40+
out = arr.toLocaleString();
41+
if ( typeof out !== 'string' ) {
42+
b.fail( 'should return a string' );
43+
}
44+
}
45+
b.toc();
46+
if ( typeof out !== 'string' ) {
47+
b.fail( 'should return a string' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 i;
51+
52+
b.tic();
53+
for ( i = 0; i < b.iterations; i++ ) {
54+
arr[ 0 ] = i;
55+
out = arr.toLocaleString();
56+
if ( typeof out !== 'string' ) {
57+
b.fail( 'should return a string' );
58+
}
59+
}
60+
b.toc();
61+
if ( typeof out !== 'string' ) {
62+
b.fail( 'should return a string' );
63+
}
64+
b.pass( 'benchmark finished' );
65+
b.end();
66+
}
67+
}
68+
69+
70+
// MAIN //
71+
72+
/**
73+
* Main execution sequence.
74+
*
75+
* @private
76+
*/
77+
function main() {
78+
var len;
79+
var min;
80+
var max;
81+
var f;
82+
var i;
83+
84+
min = 1; // 10^min
85+
max = 5; // 10^max
86+
87+
for ( i = min; i <= max; i++ ) {
88+
len = pow( 10, i );
89+
f = createBenchmark( len );
90+
bench( pkg+':toLocaleString:len='+len, f );
91+
}
92+
}
93+
94+
main();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+':toLocaleString', function benchmark( b ) {
31+
var out;
32+
var arr;
33+
var i;
34+
35+
arr = new Float64Array( 2 );
36+
37+
b.tic();
38+
for ( i = 0; i < b.iterations; i++ ) {
39+
arr[ 0 ] = i;
40+
out = arr.toLocaleString();
41+
if ( typeof out !== 'string' ) {
42+
b.fail( 'should return a string' );
43+
}
44+
}
45+
b.toc();
46+
if ( typeof out !== 'string' ) {
47+
b.fail( 'should return a string' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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 i;
51+
52+
b.tic();
53+
for ( i = 0; i < b.iterations; i++ ) {
54+
arr[ 0 ] = i;
55+
out = arr.toLocaleString();
56+
if ( typeof out !== 'string' ) {
57+
b.fail( 'should return a string' );
58+
}
59+
}
60+
b.toc();
61+
if ( typeof out !== 'string' ) {
62+
b.fail( 'should return a string' );
63+
}
64+
b.pass( 'benchmark finished' );
65+
b.end();
66+
}
67+
}
68+
69+
70+
// MAIN //
71+
72+
/**
73+
* Main execution sequence.
74+
*
75+
* @private
76+
*/
77+
function main() {
78+
var len;
79+
var min;
80+
var max;
81+
var f;
82+
var i;
83+
84+
min = 1; // 10^min
85+
max = 5; // 10^max
86+
87+
for ( i = min; i <= max; i++ ) {
88+
len = pow( 10, i );
89+
f = createBenchmark( len );
90+
bench( pkg+':toLocaleString:len='+len, f );
91+
}
92+
}
93+
94+
main();
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+':toLocaleString', function benchmark( b ) {
31+
var out;
32+
var arr;
33+
var i;
34+
35+
arr = new Int16Array( 2 );
36+
37+
b.tic();
38+
for ( i = 0; i < b.iterations; i++ ) {
39+
arr[ 0 ] = i;
40+
out = arr.toLocaleString();
41+
if ( typeof out !== 'string' ) {
42+
b.fail( 'should return a string' );
43+
}
44+
}
45+
b.toc();
46+
if ( typeof out !== 'string' ) {
47+
b.fail( 'should return a string' );
48+
}
49+
b.pass( 'benchmark finished' );
50+
b.end();
51+
});

0 commit comments

Comments
 (0)