Skip to content

Commit f4e2f6b

Browse files
bench: update benchmarks to use discreteUniform
1 parent bd45ce7 commit f4e2f6b

1 file changed

Lines changed: 42 additions & 13 deletions

File tree

  • lib/node_modules/@stdlib/number/uint64/ctor/benchmark

lib/node_modules/@stdlib/number/uint64/ctor/benchmark/benchmark.js

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,26 @@
2121
// MODULES //
2222

2323
var bench = require( '@stdlib/bench' );
24-
var randi = require( '@stdlib/random/base/randi' );
24+
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
2525
var format = require( '@stdlib/string/format' );
26+
var MAX_SAFE_INTEGER = require( '@stdlib/constants/float64/max-safe-integer' );
27+
var UINT32_MAX = require( '@stdlib/constants/uint32/max' );
2628
var pkg = require( './../package.json' ).name;
2729
var Uint64 = require( './../lib' );
2830

2931

3032
// MAIN //
3133

3234
bench( format( '%s::constructor', pkg ), function benchmark( b ) {
35+
var x;
3336
var z;
3437
var i;
3538

39+
x = discreteUniform( 100, 0, MAX_SAFE_INTEGER );
40+
3641
b.tic();
3742
for ( i = 0; i < b.iterations; i++ ) {
38-
z = new Uint64( i );
43+
z = new Uint64( x[ i % x.length ] );
3944
if ( typeof z !== 'object' ) {
4045
b.fail( 'should return a Uint64 instance' );
4146
}
@@ -49,12 +54,18 @@ bench( format( '%s::constructor', pkg ), function benchmark( b ) {
4954
});
5055

5156
bench( format( '%s::from', pkg ), function benchmark( b ) {
57+
var x;
5258
var z;
5359
var i;
5460

61+
x = discreteUniform( 100, 0, UINT32_MAX );
62+
5563
b.tic();
5664
for ( i = 0; i < b.iterations; i++ ) {
57-
z = Uint64.from( [ 0, i ] );
65+
z = Uint64.from([
66+
x[ i % x.length ],
67+
x[ (i+1) % x.length ]
68+
]);
5869
if ( typeof z !== 'object' ) {
5970
b.fail( 'should return a Uint64 instance' );
6071
}
@@ -68,12 +79,15 @@ bench( format( '%s::from', pkg ), function benchmark( b ) {
6879
});
6980

7081
bench( format( '%s::of', pkg ), function benchmark( b ) {
82+
var x;
7183
var z;
7284
var i;
7385

86+
x = discreteUniform( 100, 0, UINT32_MAX );
87+
7488
b.tic();
7589
for ( i = 0; i < b.iterations; i++ ) {
76-
z = Uint64.of( 0, i );
90+
z = Uint64.of( x[ i % x.length ], x[ (i+1) % x.length ] );
7791
if ( typeof z !== 'object' ) {
7892
b.fail( 'should return a Uint64 instance' );
7993
}
@@ -87,15 +101,20 @@ bench( format( '%s::of', pkg ), function benchmark( b ) {
87101
});
88102

89103
bench( format( '%s:toString', pkg ), function benchmark( b ) {
90-
var o;
104+
var x;
91105
var z;
106+
var o;
92107
var i;
93108

94-
z = new Uint64( randi() );
109+
x = discreteUniform( 100, 0, MAX_SAFE_INTEGER );
110+
z = [];
111+
for ( i = 0; i < x.length; i++ ) {
112+
z.push( new Uint64( x[i] ) );
113+
}
95114

96115
b.tic();
97116
for ( i = 0; i < b.iterations; i++ ) {
98-
o = z.toString();
117+
o = z[ i % z.length ].toString();
99118
if ( typeof o !== 'string' ) {
100119
b.fail( 'should return a string' );
101120
}
@@ -109,15 +128,20 @@ bench( format( '%s:toString', pkg ), function benchmark( b ) {
109128
});
110129

111130
bench( format( '%s:toJSON', pkg ), function benchmark( b ) {
112-
var o;
131+
var x;
113132
var z;
133+
var o;
114134
var i;
115135

116-
z = new Uint64( randi() );
136+
x = discreteUniform( 100, 0, MAX_SAFE_INTEGER );
137+
z = [];
138+
for ( i = 0; i < x.length; i++ ) {
139+
z.push( new Uint64( x[i] ) );
140+
}
117141

118142
b.tic();
119143
for ( i = 0; i < b.iterations; i++ ) {
120-
o = z.toJSON();
144+
o = z[ i % z.length ].toJSON();
121145
if ( typeof o !== 'object' ) {
122146
b.fail( 'should return an object' );
123147
}
@@ -131,15 +155,20 @@ bench( format( '%s:toJSON', pkg ), function benchmark( b ) {
131155
});
132156

133157
bench( format( '%s:valueOf', pkg ), function benchmark( b ) {
134-
var o;
158+
var x;
135159
var z;
160+
var o;
136161
var i;
137162

138-
z = new Uint64( randi() );
163+
x = discreteUniform( 100, 0, MAX_SAFE_INTEGER );
164+
z = [];
165+
for ( i = 0; i < x.length; i++ ) {
166+
z.push( new Uint64( x[i] ) );
167+
}
139168

140169
b.tic();
141170
for ( i = 0; i < b.iterations; i++ ) {
142-
o = z.valueOf();
171+
o = z[ i % z.length ].valueOf();
143172
if ( typeof o === 'object' ) {
144173
b.fail( 'should not return an object' );
145174
}

0 commit comments

Comments
 (0)