
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
@perfmetrics/cli
Advanced tools
Get performance metrics of js classes/functions with simple metrics reports.
Get performance metrics of js classes/functions with simple metrics reports.
First you will need to install the lib to get some metrics:
npm install @perfmetrics/lib
Next just call the lib from your code:
const perfMetrics = require("@perfmetrics/lib");
The perfMetrics is a function that takes two arguments:
name: the name of function, or ClassName.NameFunc
start: start time (higth resolution time in milliseconds)
end: end time (higth resolution time in milliseconds)
duraction: time that takes to execute the function (higth resolution time in milliseconds)
Now lets track a function:
const perfMetrics = require("@perfmetrics/lib");
function quadraticTime(n) { // n^2
let r = [];
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
r.push([i, j]);
}
}
}
const quadraticTimePerf = perfMetrics(quadraticTime);
// Now when you call quadraticTimePerf will track all the execution time
// In this case it will be logged to console.log
for (let i = 0; i < 100; i++) {
quadraticTimePerf(1000 + i);
}
Its easy to implement a new logger, but we can use the filestats logger, just install
npm install @perfmetrics/filestats
Then we can change the code to use the logger like this:
const perfMetrics = require("@perfmetrics/lib");
function quadraticTime(n) { // n^2
let r = [];
for (let i = 0; i < n; i++) {
for (let j = 0; j < n; j++) {
r.push([i, j]);
}
}
}
// Output, save file every 1 second
const fsLogger = fileStats("./stats.log", 1000);
const quadraticTimePerf = perfMetrics(quadraticTime, fsLogger);
// Now when you call quadraticTimePerf will track all the execution time
// In this case it will be logged to console.log
for (let i = 0; i < 100; i++) {
quadraticTimePerf(1000 + i);
}
Afther running the code we will get a stats.log file. To generate a report we first install package:
npm install @perfmetrics/cli --global
And finally just run:
perfmetrics -s stats.log --html stats
This will generate a stats.html report like this one: https://fsvieira.github.io/perfmetrics/
To get more information on how to use the cli, just run
perfmetrics -h
For more information check out the examples on the examples folder of this repo.
Using a proxy perfMetrics will try to keep track of the execution time of all functions generated from the proxy funcion/class, the time statistics and function information is logged using a callback function on perfMetrics, currently there in this package there is only a file logger.
Using reporter like node reports/html.js stats.log stats
will create a stats.html report.
The complexity is calculated using regressions functions (https://github.com/Tom-Alexander/regression-js) on the collected data. It goes like this:
This means that more data will give better results. It also means that a function may not correspond to code classification but that can be a good thing, why spending time otimizing functions that never reach the worst case in real cenario usage.
This is still a work in progress, but alredy a working beta.
What I would like to do in the future:
FAQs
Get performance metrics of js classes/functions with simple metrics reports.
We found that @perfmetrics/cli 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
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.