Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
vesta
Advanced tools
Readme
Simplify time measurements.
I woke up on my 26th birthday at 5 am from the blows of russian missiles. They attacked the city of Kyiv, where I live, as well as the cities in which my family and friends live. Now my country is a war zone.
We fight for democratic values, freedom, for our future! Once again Ukrainians have to stand against evil, terror, against genocide. The outcome of this war will determine what path human history is taking from now on.
💛💙 Help Ukraine! We need your support! There are dozen ways to help us, just do it!
To use library you need to have node and npm installed in your machine:
>=10
>=6
Package is continuously tested on darwin, linux and win32 platforms. All active and maintenance LTS node releases are supported.
To install the library run the following command
npm i --save vesta
import BenchMark from 'vesta';
const bench = new BenchMark();
await Promise.all([ 10, 20, 30, 40, 50, 60 ].map(async i => {
const bi = bench.start('pause');
await pause(i);
bench.end(bi);
}));
console.log(bench.report());
// ------------------------
// Label: pause
// Total: 6
// Mean: 35.166666666666664
// Q25: 22.75
// Q75: 47.5
in case of consecutive measurements use next api:
import BenchMark, { JSONReporter } from 'vesta';
const bench = new BenchMark();
bench.sequence('before cycle');
for (const iter of [ 1, 2, 3 ]) {
const iteration = bench.iteration(iter);
iteration.sequence('before iteration');
await pause(15);
iteration.sequence('15ms gone');
await pause(10);
iteration.sequence('after 10ms more');
await pause(20);
iteration.sequence('end of the iteration');
}
bench.sequence('after cycle');
console.log(bench.report(new JSONReporter()));
// [{"label":"before cycle","benchmark":0},{"label":"after cycle","benchmark":139},{"label":"before iteration","total":3,"mean":0,"q25":0,"q75":0},{"label":"15ms gone","total":3,"mean":15.333333333333334,"q25":15,"q75":15.5},{"label":"after 10ms more","total":3,"mean":10,"q25":10,"q75":10},{"label":"end of the iteration","total":3,"mean":20,"q25":20,"q75":20}]
Timers are used to fix the moment of time.
By default Timer is autodetected among process.hrtime.bigint()
performance.now()
or new Date()
depending on your environment.
All timers available from package:
import { Timer, ProcessHrtime, PerformanceNow } from 'vesta';
you can pass any of them explicitly:
import { Timer } from 'vesta';
class customTimer extends Timer {}
const bench = new BenchMark({
counter : new customTimer()
});
to implement own timer it is recomended to extends Timer
and follow it's interfece.
There are two reports available:
JSONReporter
- report in json format, usefull for external export.PlainReporter
- used by default.use custom reporter on report generation:
import BenchMark, { JSONReporter } from 'vesta';
const bench = new BenchMark();
const report = JSON.parse(bench.report(new JSONReporter()));
to pretty print numbers in report use:
import BenchMark, { PlainReporter } from 'vesta';
const bench = new BenchMark();
bench.report(new PlainReporter(), { pretty: true });
or pass pretty
as configuration object:
import BenchMark, { JSONReporter } from 'vesta';
const bench = new BenchMark({});
bench.sequence('before');
await pause(2500);
bench.sequence('after');
console.log(
bench.report(new JSONReporter(), {
pretty : {
exclude : [ 'total' ],
include : [ 'mean', 'benchmark' ]
}
})
);
// [
// { label: 'before', benchmark: 0 },
// { label: 'after', benchmark: '2s 504ms' }
// ];
where
include
- array with metric names, for which prettifier will be added.exclude
- array with metric names, for which prettifier won't be added.pass next options to BenchMark properties:
shortSingleObservations
(boolean): use short report when there are only 1 observation. true
by default.counter
(Timer): time measurer. autodetector by default.To enrich your reports, you can easily introduce new metrics to the benchmark calculations in your JavaScript code. Utilize the calculate()
method along with metrics
and items
objects within the BenchMark instance:
import BenchMark from 'vesta';
const bench = new BenchMark({});
bench.calculate({
metrics : {
over25ms : arr => arr.filter(i => i > 25).length, // number of benchmarks longer then 25ms,
// Omit calculation for quantiles
q25 : null,
q75 : null
},
items : {
// Identify benchmarks over the mean value
overMean : (arr, metrics) => arr.filter(i => i.bench > metrics.mean).map(i => i.payload)
}
});
Some of the other custom metrics you might be looking for:
metrics : {
last10 : arr => BenchMark.metrics.mean(arr.slice(-10));
}
These additions allow you to tailor the benchmarks and generate more comprehensive reports tailored to your specific needs.
Use the same API to benchmark memory usage:
import { Memory, PlainReporter } from 'vesta';
const bench = new Memory();
const b1 = bench.start('before');
const a = Array.from({ length: 1e7 });
bench.end(b1);
console.log(bench.report(new PlainReporter(), { pretty: true }));
// ------------------------
// Label: before
// Rss: 76.05MB
// HeapTotal: 76.3MB
// HeapUsed: 76.29MB
// External: 0MB
// ArrayBuffers: 0MB
Make the changes to the code and tests. Then commit to your branch. Be sure to follow the commit message conventions. Read Contributing Guidelines for details.
FAQs
Simplify time measurements
The npm package vesta receives a total of 76 weekly downloads. As such, vesta popularity was classified as not popular.
We found that vesta demonstrated a healthy version release cadence and project activity because the last version was released less than 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.