Skip to content

Commit 3e457d3

Browse files
committed
Merge branch 'develop' of https://github.com/stdlib-js/stdlib into develop
2 parents 0eb11b4 + 7af1055 commit 3e457d3

File tree

6 files changed

+932
-1
lines changed

6 files changed

+932
-1
lines changed
Lines changed: 265 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,265 @@
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 Float64Array = require( '@stdlib/array/float64' );
25+
var randu = require( '@stdlib/random/base/randu' );
26+
var isObject = require( '@stdlib/assert/is-object' );
27+
var pkg = require( './../package.json' ).name;
28+
var lowess = require( './../lib' );
29+
30+
31+
// MAIN //
32+
33+
bench( pkg, function benchmark( b ) {
34+
var result;
35+
var x;
36+
var y;
37+
var i;
38+
39+
x = new Float64Array( 100 );
40+
y = new Float64Array( x.length );
41+
for ( i = 0; i < x.length; i++ ) {
42+
x[ i ] = i;
43+
y[ i ] = ( 0.5*i ) + ( 10.0*randu() );
44+
}
45+
46+
b.tic();
47+
for ( i = 0; i < b.iterations; i++ ) {
48+
x[ 0 ] = ( randu()*100.0 ) - 50.0;
49+
y[ 99 ] = ( randu()*100.0 ) - 50.0;
50+
result = lowess( x, y );
51+
if ( typeof result !== 'object' ) {
52+
b.fail( 'should return an object' );
53+
}
54+
}
55+
b.toc();
56+
if ( !isObject( result ) ) {
57+
b.fail( 'should return an object' );
58+
}
59+
b.pass( 'benchmark finished' );
60+
b.end();
61+
});
62+
63+
bench( pkg+'::sorted', function benchmark( b ) {
64+
var result;
65+
var opts;
66+
var x;
67+
var y;
68+
var i;
69+
70+
x = new Float64Array( 100 );
71+
y = new Float64Array( x.length );
72+
for ( i = 0; i < x.length; i++ ) {
73+
x[ i ] = i;
74+
y[ i ] = ( 0.5*i ) + ( 10.0*randu() );
75+
}
76+
opts = {
77+
'sorted': true
78+
};
79+
80+
b.tic();
81+
for ( i = 0; i < b.iterations; i++ ) {
82+
x[ 0 ] = ( randu()*100.0 ) - 50.0;
83+
y[ 99 ] = ( randu()*100.0 ) - 50.0;
84+
result = lowess( x, y, opts );
85+
if ( typeof result !== 'object' ) {
86+
b.fail( 'should return an object' );
87+
}
88+
}
89+
b.toc();
90+
if ( !isObject( result ) ) {
91+
b.fail( 'should return an object' );
92+
}
93+
b.pass( 'benchmark finished' );
94+
b.end();
95+
});
96+
97+
bench( pkg+'::f=0.5', function benchmark( b ) {
98+
var result;
99+
var opts;
100+
var x;
101+
var y;
102+
var i;
103+
104+
x = new Float64Array( 100 );
105+
y = new Float64Array( x.length );
106+
for ( i = 0; i < x.length; i++ ) {
107+
x[ i ] = i;
108+
y[ i ] = ( 0.5*i ) + ( 10.0*randu() );
109+
}
110+
opts = {
111+
'f': 0.5
112+
};
113+
114+
b.tic();
115+
for ( i = 0; i < b.iterations; i++ ) {
116+
x[ 0 ] = ( randu()*100.0 ) - 50.0;
117+
y[ 99 ] = ( randu()*100.0 ) - 50.0;
118+
result = lowess( x, y, opts );
119+
if ( typeof result !== 'object' ) {
120+
b.fail( 'should return an object' );
121+
}
122+
}
123+
b.toc();
124+
if ( !isObject( result ) ) {
125+
b.fail( 'should return an object' );
126+
}
127+
b.pass( 'benchmark finished' );
128+
b.end();
129+
});
130+
131+
bench( pkg+'::delta=3', function benchmark( b ) {
132+
var result;
133+
var opts;
134+
var x;
135+
var y;
136+
var i;
137+
138+
x = new Float64Array( 100 );
139+
y = new Float64Array( x.length );
140+
for ( i = 0; i < x.length; i++ ) {
141+
x[ i ] = ( randu()*100.0 ) - 50.0;
142+
y[ i ] = ( 0.2*x[ i ] ) + ( 10.0*randu() );
143+
}
144+
opts = {
145+
'delta': 3.0
146+
};
147+
148+
b.tic();
149+
for ( i = 0; i < b.iterations; i++ ) {
150+
x[ 0 ] = ( randu()*100.0 ) - 50.0;
151+
y[ 99 ] = ( 0.2*x[ 99 ] ) + ( 10.0*randu() );
152+
result = lowess( x, y, opts );
153+
if ( typeof result !== 'object' ) {
154+
b.fail( 'should return an object' );
155+
}
156+
}
157+
b.toc();
158+
if ( !isObject( result ) ) {
159+
b.fail( 'should return an object' );
160+
}
161+
b.pass( 'benchmark finished' );
162+
b.end();
163+
});
164+
165+
bench( pkg+'::delta=0', function benchmark( b ) {
166+
var result;
167+
var opts;
168+
var x;
169+
var y;
170+
var i;
171+
172+
x = new Float64Array( 100 );
173+
y = new Float64Array( x.length );
174+
for ( i = 0; i < x.length; i++ ) {
175+
x[ i ] = ( randu()*100.0 ) - 50.0;
176+
y[ i ] = ( 0.2*x[ i ] ) + ( 10.0*randu() );
177+
}
178+
opts = {
179+
'delta': 0.0
180+
};
181+
182+
b.tic();
183+
for ( i = 0; i < b.iterations; i++ ) {
184+
x[ 0 ] = ( randu()*100.0 ) - 50.0;
185+
y[ 99 ] = ( 0.2*x[ 99 ] ) + ( 10.0*randu() );
186+
result = lowess( x, y, opts );
187+
if ( typeof result !== 'object' ) {
188+
b.fail( 'should return an object' );
189+
}
190+
}
191+
b.toc();
192+
if ( !isObject( result ) ) {
193+
b.fail( 'should return an object' );
194+
}
195+
b.pass( 'benchmark finished' );
196+
b.end();
197+
});
198+
199+
bench( pkg+'::nsteps=1', function benchmark( b ) {
200+
var result;
201+
var opts;
202+
var x;
203+
var y;
204+
var i;
205+
206+
x = new Float64Array( 100 );
207+
y = new Float64Array( x.length );
208+
for ( i = 0; i < x.length; i++ ) {
209+
x[ i ] = ( randu()*100.0 ) - 50.0;
210+
y[ i ] = ( 0.2*x[ i ] ) + ( 10.0*randu() );
211+
}
212+
opts = {
213+
'nsteps': 1
214+
};
215+
216+
b.tic();
217+
for ( i = 0; i < b.iterations; i++ ) {
218+
x[ 0 ] = ( randu()*100.0 ) - 50.0;
219+
y[ 99 ] = ( 0.2*x[ 99 ] ) + ( 10.0*randu() );
220+
result = lowess( x, y, opts );
221+
if ( typeof result !== 'object' ) {
222+
b.fail( 'should return an object' );
223+
}
224+
}
225+
b.toc();
226+
if ( !isObject( result ) ) {
227+
b.fail( 'should return an object' );
228+
}
229+
b.pass( 'benchmark finished' );
230+
b.end();
231+
});
232+
233+
bench( pkg+'::nsteps=2', function benchmark( b ) {
234+
var result;
235+
var opts;
236+
var x;
237+
var y;
238+
var i;
239+
240+
x = new Float64Array( 100 );
241+
y = new Float64Array( x.length );
242+
for ( i = 0; i < x.length; i++ ) {
243+
x[ i ] = ( randu()*100.0 ) - 50.0;
244+
y[ i ] = ( 0.2*x[ i ] ) + ( 10.0*randu() );
245+
}
246+
opts = {
247+
'nsteps': 2
248+
};
249+
250+
b.tic();
251+
for ( i = 0; i < b.iterations; i++ ) {
252+
x[ 0 ] = ( randu()*100.0 ) - 50.0;
253+
y[ 99 ] = ( 0.2*x[ 99 ] ) + ( 10.0*randu() );
254+
result = lowess( x, y, opts );
255+
if ( typeof result !== 'object' ) {
256+
b.fail( 'should return an object' );
257+
}
258+
}
259+
b.toc();
260+
if ( !isObject( result ) ) {
261+
b.fail( 'should return an object' );
262+
}
263+
b.pass( 'benchmark finished' );
264+
b.end();
265+
});

0 commit comments

Comments
 (0)