Skip to content

Commit 16884bf

Browse files
authored
Add benchmark for Erlang logpdf function
Signed-off-by: Kamal Singh Rautela <130351010+rautelaKamal@users.noreply.github.com>
1 parent 6e96f8a commit 16884bf

1 file changed

Lines changed: 76 additions & 0 deletions

File tree

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* @license Apache-2.0
3+
*
4+
* Copyright (c) 2026 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 resolve = require( 'path' ).resolve;
24+
var bench = require( '@stdlib/bench' );
25+
var Float64Array = require( '@stdlib/array/float64' );
26+
var uniform = require( '@stdlib/random/base/uniform' );
27+
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
28+
var isnan = require( '@stdlib/math/base/assert/is-nan' );
29+
var EPS = require( '@stdlib/constants/float64/eps' );
30+
var tryRequire = require( '@stdlib/utils/try-require' );
31+
var format = require( '@stdlib/string/format' );
32+
var pkg = require( './../package.json' ).name;
33+
34+
35+
// VARIABLES //
36+
37+
var logpdf = tryRequire( resolve( __dirname, './../lib/native.js' ) );
38+
var opts = {
39+
'skip': ( logpdf instanceof Error )
40+
};
41+
42+
43+
// MAIN //
44+
45+
bench( format( '%s::native', pkg ), opts, function benchmark( b ) {
46+
var lambda;
47+
var len;
48+
var k;
49+
var x;
50+
var y;
51+
var i;
52+
53+
len = 100;
54+
x = new Float64Array( len );
55+
k = new Float64Array( len );
56+
lambda = new Float64Array( len );
57+
for ( i = 0; i < len; i++ ) {
58+
x[ i ] = uniform( EPS, 50.0 );
59+
k[ i ] = discreteUniform( 1, 10 );
60+
lambda[ i ] = uniform( EPS, 20.0 );
61+
}
62+
63+
b.tic();
64+
for ( i = 0; i < b.iterations; i++ ) {
65+
y = logpdf( x[ i % len ], k[ i % len ], lambda[ i % len ] );
66+
if ( isnan( y ) ) {
67+
b.fail( 'should not return NaN' );
68+
}
69+
}
70+
b.toc();
71+
if ( isnan( y ) ) {
72+
b.fail( 'should not return NaN' );
73+
}
74+
b.pass( 'benchmark finished' );
75+
b.end();
76+
} );

0 commit comments

Comments
 (0)