![Maven Central Adds Sigstore Signature Validation](https://cdn.sanity.io/images/cgdhsj6q/production/7da3bc8a946cfb5df15d7fcf49767faedc72b483-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Maven Central Adds Sigstore Signature Validation
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
@jalik/benchmark
Advanced tools
To measure a single synchronous function, use measureSync(func, iterations)
.
import { measureSync } from '@jalik/benchmark';
function logHelloWorld () {
console.log('hello world');
}
// Run function 1000 times
const result = measureSync(logHelloWorld, 1000);
To measure an asynchronous function, use measure(asyncFunc, iterations)
.
import { measure } from '@jalik/benchmark';
function logHelloWorld () {
setTimeout(() => {
console.log('hello world')
}, 2000);
}
// Run function 100 times
measure(logHelloWorld, 100).then((result) => {
// do something with the result...
});
The result object of a measure looks like this:
interface MeasureResult {
average: number;
fastest: number;
ips: number;
ipsAccuracy: number;
ipsRounded: number;
iterations: number;
median: number;
slowest: number;
total: number;
}
You can show measure result in the console with logMeasureResult(result)
.
import { logMeasureResult } from '@jalik/benchmark';
const test = () => console.log("Hello World");
const iterations = 1000;
// sync version.
const result1 = measureSync(test, iterations);
logMeasureResult(result1);
// async version.
measure(test, iterations).then((result2) => {
logMeasureResult(result2);
});
iterations/s: 82 ±-0.36%
total: 1224.95 ms
average: 12.25 ms
median: 11.93 ms
fastest: 11.58 ms
slowest: 24.43 ms
To measure several synchronous functions, use benchmarkSync(jobs, iterations)
.
import { benchmarkSync } from '@jalik/benchmark';
function incrementPlusPlus () {
for (let i = 0; i < 10000; i++) {
// do something
}
}
function incrementPlusEqual () {
for (let i = 0; i < 10000; i += 1) {
// do something
}
}
const jobs = {
incrementPlusPlus,
incrementPlusEqual,
};
// Run each function 1000 times
const result = benchmarkSync(jobs, 1000);
To measure several asynchronous functions, use benchmark(jobs, iterations)
.
import { benchmark } from '@jalik/benchmark';
function job1 () {
// return promise...;
}
function job2 () {
// return promise...;
}
const jobs = {
job1,
job2,
};
// Run each function 1000 times
benchmark(jobs, 1000).then((result) => {
// do something with the result
});
The result object of a benchmark looks like this:
interface BenchmarkResult {
[key: string]: MeasureResult;
}
You can show benchmark result in the console with logBenchmarkResult(result)
.
import {
benchmark,
benchmarkSync,
logBenchmarkResult
} from '@jalik/benchmark';
// sync version
const result1 = benchmarkSync({
doSomethingSlow: () => { /* ... */ },
doSomethingFast: () => { /* ... */ },
}, 1000);
logBenchmarkResult(result1);
// async version
benchmarkSync({
doSomethingSlow: () => { /* ... */ },
doSomethingFast: () => { /* ... */ },
}, 1000).then((result2) => {
logBenchmarkResult(result2);
});
#1 doSomethingFast
iterations/s: 1250 ±0.00%
total: 8.00 ms
average: 0.80 ms
median: 1.00 ms
fastest: 0.00 ms
slowest: 1.00 ms
#2 doSomethingSlow
iterations/s: 40 ±0.00%
total: 250.00 ms
average: 25.00 ms
median: 25.00 ms
fastest: 24.00 ms
slowest: 27.00 ms
History of releases is in the changelog.
The code is released under the MIT License.
v2.0.3 (2023-09-15)
FAQs
Utilities to benchmark code.
We found that @jalik/benchmark demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.