Registry / testing / nv-facutil-simple-test

nv-facutil-simple-test

JSON →
library0.0.22jsnpmunverified

nv-facutil-simple-test is an early-stage (version 0.0.22) JavaScript utility library designed for straightforward function execution and performance benchmarking. It provides mechanisms to execute synchronous functions (`sync`) and asynchronous functions (`async`) a specified number of times, measuring their execution cost. Additionally, it offers a `cmp` utility to compare the performance of multiple functions against each other. The library aims to offer a minimalistic API for quick, ad-hoc performance tests and basic function verification. Given its pre-1.0 versioning, it is currently in active development with an unspecified release cadence, implying that breaking changes may occur frequently. Its primary differentiator is its directness and simplicity for measuring execution time.

npm install nv-facutil-simple-test
INSTALL
IMPORT
SIG · NV-FACUTIL-SIMPLE-
N
nv-facutil-simple-test
testingjavascriptv0.0.22
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

sync
import { sync } from 'nv-facutil-simple-test';
const sync = require('nv-facutil-simple-test').sync;
CommonJS import for named exports; ESM is preferred in modern applications.
async
import { async } from 'nv-facutil-simple-test';
const async = require('nv-facutil-simple-test').async;
The 'async' export is a function, not a keyword; ensure proper import for the function.
cmp
import { cmp } from 'nv-facutil-simple-test';
const { cmp } = require('nv-facutil-simple-test'); // Often missed in common usage examples
The 'cmp' function is used for comparing multiple function performances and is a named export.

This quickstart demonstrates how to use `sync` for synchronous tasks, `async` for asynchronous (Promise-based) operations, and `cmp` to benchmark the performance of several functions, illustrating basic usage patterns for each.

import { sync, async, cmp } from 'nv-facutil-simple-test'; // Example 1: Synchronous function testing function addNumbers(a, b) { let sum = 0; for (let i = 0; i < 100; i++) { sum += a + b; } return sum; } console.log('Synchronous test results:'); const syncResult = sync(100000, addNumbers, 5, 10); console.log(syncResult); // Example 2: Asynchronous function testing function delayedGreeting(name, delay) { return new Promise(resolve => { setTimeout(() => resolve(`Hello, ${name} after ${delay}ms`), delay); }); } console.log('\nAsynchronous test results (awaiting promise):'); async function runAsyncTest() { const asyncResult = await async(3, delayedGreeting, 'World', 100); console.log(asyncResult); } runAsyncTest(); // Example 3: Compare performance of multiple functions class Cnode { constructor(a, b) { this.a = a; this.b = b; } } function Fnode(a, b) { this.a = a; this.b = b; } const new_cnd = (a, b) => new Cnode(a, b); const new_fnd = (a, b) => new Fnode(a, b); const plain_obj = (a, b) => ({ a, b }); console.log('\nComparing object creation methods:'); const comparisonResults = cmp(1000000, [new_cnd, new_fnd, plain_obj], 111, 222); console.log(comparisonResults);
Debug
Known issues
breakingAs a package in the 0.0.x version range, `nv-facutil-simple-test` is considered highly unstable. Expect frequent, unannounced breaking changes in its API, behavior, and exports between minor and patch versions. It is not suitable for production use where API stability is required.
fix
Pin to exact patch versions (`~0.0.x`) or be prepared to refactor code frequently. Consider using more mature benchmarking libraries for production environments.
affects: >=0.0.1
gotchaThe `async` function returns a Promise that resolves with the testing results, rather than the results directly. Developers must `await` the returned Promise or chain `.then()` to access the performance metrics. Failing to do so will result in accessing a pending Promise object.
fix
Always use `await` with the `async` function call in an `async` context, or use `.then()` for Promise resolution: `const results = await async(...)` or `async(...).then(results => ...)`.
affects: >=0.0.1
gotchaThe `cmp` function, though demonstrated in the README's examples, is not explicitly included in the `require` statement in the `usage` section. This can lead to a `ReferenceError` if only `sync`, `async`, and `Ahook` are imported via CommonJS `require`.
fix
When using CommonJS, ensure all desired exports are explicitly destructured: `const {sync, async, Ahook, cmp} = require('nv-facutil-simple-test');`. For ESM, use `import { sync, async, Ahook, cmp } from 'nv-facutil-simple-test';`.
affects: >=0.0.1
gotchaThe package currently only provides CommonJS (`require()`) examples in its README. While modern Node.js environments often support ESM (`import`), direct `import` statements might behave unexpectedly or require specific `package.json` configurations (`"type": "module"`) depending on how the package is bundled and exported, especially in `0.0.x` versions.
fix
For CommonJS environments, stick to `require()`. For ESM environments, try `import { ... } from 'nv-facutil-simple-test';`. If issues arise, check the Node.js module resolution settings or consider using a transpiler.
affects: >=0.0.1
Errors
Common errors & fixes
ReferenceError: cmp is not defined
The 'cmp' function was used without being explicitly imported from the 'nv-facutil-simple-test' package.
fix
Ensure 'cmp' is included in your import statement: `const { sync, async, cmp } = require('nv-facutil-simple-test');` or `import { sync, async, cmp } from 'nv-facutil-simple-test';`
Promise { <pending> } (when trying to log async results directly)
The 'async' function returns a Promise. Logging the return value directly before it resolves will show the pending Promise object, not its resolved value.
fix
You must `await` the result of the `async` call (within an `async` function) or use a `.then()` callback to access the resolved performance metrics. Example: `const result = await async(...)` or `async(...).then(result => console.log(result))`.
Upgrade
Version history
0.0.22latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
nv-facutil-simple-test — npm install nv-facutil-simple-test · libregistry