Skip to content

Commit 9accd30

Browse files
committed
Update examples
1 parent 6df7973 commit 9accd30

File tree

8 files changed

+67
-28
lines changed

8 files changed

+67
-28
lines changed

lib/node_modules/@stdlib/bench/harness/examples/async.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bench( 'async', opts, function benchmark( b ) {
4242
return setTimeout( next, 0 );
4343
}
4444
b.toc();
45-
b.pass( 'benchmark success!' );
45+
b.pass( 'benchmark finished' );
4646
after();
4747
}
4848

lib/node_modules/@stdlib/bench/harness/examples/async_auto_iterations.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bench( 'async', opts, function benchmark( b ) {
4242
return setTimeout( next, 0 );
4343
}
4444
b.toc();
45-
b.pass( 'benchmark success!' );
45+
b.pass( 'benchmark finished' );
4646
after();
4747
}
4848

lib/node_modules/@stdlib/bench/harness/examples/auto_iterations.js

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
'use strict';
2222

23-
var randu = require( '@stdlib/random/base/randu' );
2423
var isnan = require( '@stdlib/math/base/assert/is-nan' );
2524
var bench = require( './../lib' );
2625

@@ -31,25 +30,73 @@ var opts = {
3130
};
3231

3332
// Run benchmarks:
34-
bench( 'Math.sin', opts, function benchmark( b ) {
33+
bench( 'cross product (function)', opts, function benchmark( b ) {
34+
var out;
3535
var x;
3636
var y;
3737
var i;
38+
var j;
39+
40+
out = [ 0.0, 0.0, 0.0 ];
41+
x = [ 1.0, 2.0, 3.0 ];
42+
y = [ 4.0, 5.0, 6.0 ];
43+
44+
b.tic();
45+
for ( i = 0; i < b.iterations; i++ ) {
46+
x[ 0 ] = i + 1.0;
47+
x[ 1 ] = x[ 0 ] + 1.0;
48+
x[ 2 ] = x[ 1 ] + 1.0;
49+
cross( out, x, y );
50+
j = i % 3;
51+
if ( out[ j ] !== out[ j ] ) {
52+
b.fail( 'something went wrong!' );
53+
}
54+
}
55+
b.toc();
56+
57+
if ( isnan( out[ 0 ] ) ) {
58+
b.fail( 'something went wrong!' );
59+
}
60+
b.pass( 'benchmark finished' );
61+
b.end();
62+
63+
function cross( out, a, b ) {
64+
out[ 0 ] = (a[1]*b[2]) - (a[2]*b[1]);
65+
out[ 1 ] = (a[2]*b[0]) - (a[0]*b[2]);
66+
out[ 2 ] = (a[0]*b[1]) - (a[1]*b[0]);
67+
return out;
68+
}
69+
});
70+
71+
bench( 'cross product (inlined)', opts, function benchmark( b ) {
72+
var out;
73+
var x;
74+
var y;
75+
var i;
76+
var j;
77+
78+
out = [ 0.0, 0.0, 0.0 ];
79+
x = [ 1.0, 2.0, 3.0 ];
80+
y = [ 4.0, 5.0, 6.0 ];
3881

3982
b.tic();
4083
for ( i = 0; i < b.iterations; i++ ) {
41-
x = (randu()*100.0) - 50.0;
42-
y = Math.sin( x ); // eslint-disable-line stdlib/no-builtin-math
43-
if ( y < -1.0 || y > 1.0 ) {
84+
x[ 0 ] = i + 1.0;
85+
x[ 1 ] = x[ 0 ] + 1.0;
86+
x[ 2 ] = x[ 1 ] + 1.0;
87+
out[ 0 ] = (x[1]*y[2]) - (x[2]*y[1]);
88+
out[ 1 ] = (x[2]*y[0]) - (x[0]*y[2]);
89+
out[ 2 ] = (x[0]*y[1]) - (x[1]*y[0]);
90+
j = i % 3;
91+
if ( out[ j ] !== out[ j ] ) {
4492
b.fail( 'something went wrong!' );
4593
}
4694
}
4795
b.toc();
4896

49-
if ( isnan( y ) ) {
97+
if ( isnan( out[ 0 ] ) ) {
5098
b.fail( 'something went wrong!' );
51-
} else {
52-
b.pass( 'benchmark success!' );
5399
}
100+
b.pass( 'benchmark finished' );
54101
b.end();
55102
});

lib/node_modules/@stdlib/bench/harness/examples/harness.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,7 @@ bench( 'sin', opts, function benchmark( b ) {
6161

6262
if ( isnan( y ) ) {
6363
b.fail( 'something went wrong!' );
64-
} else {
65-
b.pass( 'benchmark success!' );
6664
}
65+
b.pass( 'benchmark finished' );
6766
b.end();
6867
});

lib/node_modules/@stdlib/bench/harness/examples/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ bench( 'Math.sin', opts, function benchmark( b ) {
4747

4848
if ( isnan( y ) ) {
4949
b.fail( 'something went wrong!' );
50-
} else {
51-
b.pass( 'benchmark success!' );
5250
}
51+
b.pass( 'benchmark finished' );
5352
b.end();
5453
});
5554

@@ -70,8 +69,7 @@ bench( 'sin', opts, function benchmark( b ) {
7069

7170
if ( isnan( y ) ) {
7271
b.fail( 'something went wrong!' );
73-
} else {
74-
b.pass( 'benchmark success!' );
7572
}
73+
b.pass( 'benchmark finished' );
7674
b.end();
7775
});

lib/node_modules/@stdlib/bench/harness/examples/mixed_sync_async.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ bench( 'Math.sin', opts, function benchmark( b ) {
4747

4848
if ( isnan( y ) ) {
4949
b.fail( 'something went wrong!' );
50-
} else {
51-
b.pass( 'benchmark success!' );
5250
}
51+
b.pass( 'benchmark finished' );
5352
b.end();
5453
});
5554

@@ -68,7 +67,7 @@ bench( 'async (1)', opts, function benchmark( b ) {
6867
return setTimeout( next, 200 );
6968
}
7069
b.toc();
71-
b.pass( 'benchmark success!' );
70+
b.pass( 'benchmark finished' );
7271
after();
7372
}
7473

@@ -98,9 +97,8 @@ bench( 'sin', opts, function benchmark( b ) {
9897

9998
if ( isnan( y ) ) {
10099
b.fail( 'something went wrong!' );
101-
} else {
102-
b.pass( 'benchmark success!' );
103100
}
101+
b.pass( 'benchmark finished' );
104102
b.end();
105103
});
106104

@@ -119,7 +117,7 @@ bench( 'async (2)', opts, function benchmark( b ) {
119117
return setTimeout( next, 0 );
120118
}
121119
b.toc();
122-
b.pass( 'benchmark success!' );
120+
b.pass( 'benchmark finished' );
123121
after();
124122
}
125123

lib/node_modules/@stdlib/bench/harness/examples/multiple_harness.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,8 @@ bench1( 'Math.sin', opts, function benchmark( b ) {
7171

7272
if ( isnan( y ) ) {
7373
b.fail( 'something went wrong!' );
74-
} else {
75-
b.pass( 'benchmark success!' );
7674
}
75+
b.pass( 'benchmark finished' );
7776
b.end();
7877
});
7978

@@ -94,8 +93,7 @@ bench2( 'sin', opts, function benchmark( b ) {
9493

9594
if ( isnan( y ) ) {
9695
b.fail( 'something went wrong!' );
97-
} else {
98-
b.pass( 'benchmark success!' );
9996
}
97+
b.pass( 'benchmark finished' );
10098
b.end();
10199
});

lib/node_modules/@stdlib/bench/harness/examples/skip.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ bench( 'Math.sin', opts, function benchmark( b ) {
4747

4848
if ( isnan( y ) ) {
4949
b.fail( 'something went wrong!' );
50-
} else {
51-
b.pass( 'benchmark success!' );
5250
}
51+
b.pass( 'benchmark finished' );
5352
b.end();
5453
});

0 commit comments

Comments
 (0)