
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
execution-time-decorators
Advanced tools
The `timer()` decorator starts a timer you can use to track how long an operation takes. Suitable for use in both synchronous and asynchronous methods both in Node.js and Browser apps.
The timer()
decorator starts a timer you can use to track how long an operation takes.
Suitable for use in both synchronous and asynchronous methods both in Node.js and Browser apps.
Call require to get the instance:
const { timer } = require('execution-time-decorators');
Or in ES6 and TS:
import { timer } from 'execution-time-decorators';
class ExampleTimers {
@timer()
readSync(filepath: string) {
return fs.readFileSync(filepath);
}
@timer()
async readAsync(filepath: string) {
return fs.promises.readFile(filepath);
}
@timer({ logger: pino })
async readAsyncP(filepath: string) {
return fs.promises.readFile(filepath);
}
@timer({ hr: true })
static readSync(filepath: string) {
return fs.readFileSync(filepath);
}
@timer({ logger: pino, hr: true })
static async readAsync(filepath: string) {
return fs.promises.readFile(filepath);
}
}
[timer] [ExampleTimers::readSync]: begin
[timer] [ExampleTimers::readSync]: timer 0.008s
[timer] [ExampleTimers::readAsync]: begin
[timer] [ExampleTimers::readAsync]: timer 0.010s
{"level":30,"time":1687023007188,"pid":56981,"hostname":"192.168.68.52","msg":"[timer] [ExampleTimers::readAsyncP]: begin"}
{"level":30,"time":1687023007205,"pid":56981,"hostname":"192.168.68.52","msg":"[timer] [ExampleTimers::readAsyncP]: timer 0.017s"}
[timer] [static ExampleTimers::readSync]: begin
[timer] [static ExampleTimers::readSync]: timer 7212041ns
{"level":30,"time":1687023007212,"pid":56981,"hostname":"192.168.68.52","msg":"[timer] [static ExampleTimers::readAsync]: begin"}
{"level":30,"time":1687023007231,"pid":56981,"hostname":"192.168.68.52","msg":"[timer] [static ExampleTimers::readAsync]: timer 18302917ns"}
Type: object
Type: { log: (...args: any[]) => void } | { info: (...args: any[]) => void }
Default: console
Default or your current logger.
Type: boolean
Default: false
When true, arguments passed to the method will be print to the logs.
Type: boolean
Default: false
Print execution time in nanoseconds.
FAQs
The `timer()` decorator starts a timer you can use to track how long an operation takes. Suitable for use in both synchronous and asynchronous methods both in Node.js and Browser apps.
The npm package execution-time-decorators receives a total of 615 weekly downloads. As such, execution-time-decorators popularity was classified as not popular.
We found that execution-time-decorators 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.