diff --git a/lib/node_modules/@stdlib/stats/kde2d/benchmark/benchmark.js b/lib/node_modules/@stdlib/stats/kde2d/benchmark/benchmark.js new file mode 100644 index 000000000000..56b8415b2cea --- /dev/null +++ b/lib/node_modules/@stdlib/stats/kde2d/benchmark/benchmark.js @@ -0,0 +1,164 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 The Stdlib Authors. +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +'use strict'; + +// MODULES // + +var bench = require( '@stdlib/bench' ); +var Float64Array = require( '@stdlib/array/float64' ); +var normal = require( '@stdlib/random/base/normal' ); +var isObject = require( '@stdlib/assert/is-object' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var kde2d = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var result; + var x; + var y; + var i; + + x = new Float64Array( 100 ); + y = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = normal( 3.0, 1.2 ); + y[ i ] = normal( 10.0, 4.5 ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] = normal( 3.0, 1.2 ); + y[ 99 ] = normal( 10.0, 4.5 ); + result = kde2d( x, y ); + if ( typeof result !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( result ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:n=10', pkg ), function benchmark( b ) { + var result; + var opts; + var x; + var y; + var i; + + x = new Float64Array( 100 ); + y = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = normal( 3.0, 1.2 ); + y[ i ] = normal( 10.0, 4.5 ); + } + opts = { + 'n': 10 + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] = normal( 3.0, 1.2 ); + y[ 99 ] = normal( 10.0, 4.5 ); + result = kde2d( x, y, opts ); + if ( typeof result !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( result ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:kernel=epanechnikov', pkg ), function benchmark( b ) { + var result; + var opts; + var x; + var y; + var i; + + x = new Float64Array( 100 ); + y = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = normal( 3.0, 1.2 ); + y[ i ] = normal( 10.0, 4.5 ); + } + opts = { + 'kernel': 'epanechnikov' + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] = normal( 3.0, 1.2 ); + y[ 99 ] = normal( 10.0, 4.5 ); + result = kde2d( x, y, opts ); + if ( typeof result !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( result ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s:h=[0.5,0.5]', pkg ), function benchmark( b ) { + var result; + var opts; + var x; + var y; + var i; + + x = new Float64Array( 100 ); + y = new Float64Array( x.length ); + for ( i = 0; i < x.length; i++ ) { + x[ i ] = normal( 3.0, 1.2 ); + y[ i ] = normal( 10.0, 4.5 ); + } + opts = { + 'h': [ 0.5, 0.5 ] + }; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + x[ 0 ] = normal( 3.0, 1.2 ); + y[ 99 ] = normal( 10.0, 4.5 ); + result = kde2d( x, y, opts ); + if ( typeof result !== 'object' ) { + b.fail( 'should return an object' ); + } + } + b.toc(); + if ( !isObject( result ) ) { + b.fail( 'should return an object' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/stats/kde2d/package.json b/lib/node_modules/@stdlib/stats/kde2d/package.json index 4322a353621b..24abba25ee9a 100644 --- a/lib/node_modules/@stdlib/stats/kde2d/package.json +++ b/lib/node_modules/@stdlib/stats/kde2d/package.json @@ -15,6 +15,7 @@ ], "main": "./lib", "directories": { + "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", "lib": "./lib",