From 0ca2bfd40ae989f68a2681c69961aa796e4e0641 Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 21 May 2026 08:14:12 +0000 Subject: [PATCH] bench: add benchmarks to `@stdlib/object/any-own-by` Added missing benchmark/benchmark.js (a benchmark suite is present in 25/26 = 96% of @stdlib/object siblings, and some benchmark directory is present in 96.5% of non-tooling stdlib packages that ship a lib/main.js implementation; any-own-by was the sole namespace member with no benchmark directory). Registered the directory in package.json `directories` ("benchmark": "./benchmark"; present in 25/25 of the siblings that ship benchmarks). The benchmark mirrors the sibling `@stdlib/object/any-in-by`, exercising the predicate path against built-in and manual-loop baselines over own enumerable properties. No public behavior, signatures, or test expectations change. --- .../object/any-own-by/benchmark/benchmark.js | 137 ++++++++++++++++++ .../@stdlib/object/any-own-by/package.json | 1 + 2 files changed, 138 insertions(+) create mode 100644 lib/node_modules/@stdlib/object/any-own-by/benchmark/benchmark.js diff --git a/lib/node_modules/@stdlib/object/any-own-by/benchmark/benchmark.js b/lib/node_modules/@stdlib/object/any-own-by/benchmark/benchmark.js new file mode 100644 index 000000000000..0b8aff6bf888 --- /dev/null +++ b/lib/node_modules/@stdlib/object/any-own-by/benchmark/benchmark.js @@ -0,0 +1,137 @@ +/** +* @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 isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var isnan = require( '@stdlib/math/base/assert/is-nan' ); +var format = require( '@stdlib/string/format' ); +var pkg = require( './../package.json' ).name; +var anyOwnBy = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var bool; + var obj; + var i; + + function predicate( v ) { + return isnan( v ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = { + 'a': i, + 'b': i+1, + 'c': i+2, + 'd': i+3, + 'e': i+4, + 'f': NaN + }; + bool = anyOwnBy( obj, predicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::built-in', pkg ), function benchmark( b ) { + var bool; + var keys; + var obj; + var i; + + function predicate( v ) { + return isnan( v ); + } + function testPredicate( key ) { + return predicate( obj[ key ] ); + } + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = { + 'a': i, + 'b': i+1, + 'c': i+2, + 'd': i+3, + 'e': i+4, + 'f': NaN + }; + keys = Object.keys( obj ); + bool = keys.some( testPredicate ); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); + +bench( format( '%s::loop', pkg ), function benchmark( b ) { + var bool; + var keys; + var obj; + var i; + var j; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + obj = { + 'a': i, + 'b': i+1, + 'c': i+2, + 'd': i+3, + 'e': i+4, + 'f': NaN + }; + keys = Object.keys( obj ); + bool = false; + for ( j = 0; j < keys.length; j++ ) { + if ( isnan( obj[ keys[j] ] ) ) { + bool = true; + break; + } + } + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should be a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/object/any-own-by/package.json b/lib/node_modules/@stdlib/object/any-own-by/package.json index 3559f0c9d3f3..92c9bffc1862 100644 --- a/lib/node_modules/@stdlib/object/any-own-by/package.json +++ b/lib/node_modules/@stdlib/object/any-own-by/package.json @@ -15,6 +15,7 @@ ], "main": "./lib", "directories": { + "benchmark": "./benchmark", "doc": "./docs", "example": "./examples", "lib": "./lib",