Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bench: move random number generation outside the benchmarking loops
Browse files Browse the repository at this point in the history
---
type: pre_commit_static_analysis_report
description: Results of running static analysis checks when committing changes.
report:
  - task: lint_filenames
    status: passed
  - task: lint_editorconfig
    status: passed
  - task: lint_markdown
    status: na
  - task: lint_package_json
    status: na
  - task: lint_repl_help
    status: na
  - task: lint_javascript_src
    status: na
  - task: lint_javascript_cli
    status: na
  - task: lint_javascript_examples
    status: na
  - task: lint_javascript_tests
    status: na
  - task: lint_javascript_benchmarks
    status: passed
  - task: lint_python
    status: na
  - task: lint_r
    status: na
  - task: lint_c_src
    status: na
  - task: lint_c_examples
    status: na
  - task: lint_c_benchmarks
    status: na
  - task: lint_c_tests_fixtures
    status: na
  - task: lint_shell
    status: na
  - task: lint_typescript_declarations
    status: na
  - task: lint_typescript_tests
    status: na
  - task: lint_license_headers
    status: passed
---

---
type: pre_push_report
description: Results of running various checks prior to pushing changes.
report:
  - task: run_javascript_examples
    status: na
  - task: run_c_examples
    status: na
  - task: run_cpp_examples
    status: na
  - task: run_javascript_readme_examples
    status: na
  - task: run_c_benchmarks
    status: na
  - task: run_cpp_benchmarks
    status: na
  - task: run_fortran_benchmarks
    status: na
  - task: run_javascript_benchmarks
    status: na
  - task: run_julia_benchmarks
    status: na
  - task: run_python_benchmarks
    status: na
  - task: run_r_benchmarks
    status: na
  - task: run_javascript_tests
    status: na
---
anandkaranubc committed Jan 29, 2025
1 parent 48f82a2 commit dccad5f
Showing 11 changed files with 305 additions and 118 deletions.
Original file line number Diff line number Diff line change
@@ -21,8 +21,9 @@
// MODULES //

var bench = require( '@stdlib/bench' );
var round = require( '@stdlib/math/base/special/round' );
var randu = require( '@stdlib/random/base/randu' );
var Float64Array = require( '@stdlib/array/float64' );
var uniform = require( '@stdlib/random/base/uniform' );
var discreteUniform = require( '@stdlib/random/base/discrete-uniform' );
var isnan = require( '@stdlib/math/base/assert/is-nan' );
var pkg = require( './../package.json' ).name;
var cdf = require( './../lib' );
@@ -31,20 +32,29 @@ var cdf = require( './../lib' );
// MAIN //

bench( pkg, function benchmark( b ) {
var len;
var N;
var K;
var n;
var x;
var y;
var i;

len = 100;
x = new Float64Array( len );
N = new Float64Array( len );
K = new Float64Array( len );
n = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = discreteUniform( 1, 50 );
N[ i ] = discreteUniform( 1, 100 );
K[ i ] = discreteUniform( 1, N[ i ] );
n[ i ] = discreteUniform( 1, N[ i ] );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = round( randu()*50.0 );
N = round( randu()*100.0 );
K = round( randu()*N );
n = round( randu()*N );
y = cdf( x, N, K, n );
y = cdf( x[ i % len ], N[ i % len ], K[ i % len ], n[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}
@@ -59,22 +69,27 @@ bench( pkg, function benchmark( b ) {

bench( pkg+':factory', function benchmark( b ) {
var mycdf;
var len;
var N;
var K;
var n;
var x;
var y;
var i;

N = round( randu()*100.0 );
K = round( randu()*N );
n = round( randu()*N );
len = 100;
N = discreteUniform( 1, 100 );
K = discreteUniform( 1, N );
n = discreteUniform( 1, N );
mycdf = cdf.factory( N, K, n );
x = new Float64Array( len );
for ( i = 0; i < len; i++ ) {
x[ i ] = uniform( 0.0, 40.0 );
}

b.tic();
for ( i = 0; i < b.iterations; i++ ) {
x = randu()*40.0;
y = mycdf( x );
y = mycdf( x[ i % len ] );
if ( isnan( y ) ) {
b.fail( 'should not return NaN' );
}

Large diffs are not rendered by default.

0 comments on commit dccad5f

Please sign in to comment.