Security News
PyPI Introduces Digital Attestations to Strengthen Python Package Security
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
@universal-packages/time-measurer
Advanced tools
Time Measurer is a simple wrap for process.hrtime
to measure time with procession and express that time easily through formatted representations, anytime you want to express how much a query or a request took at code level you may want to give this a try.
npm install @universal-packages/time-measurer
Class TimeMeasurer
provides an instantiable interface to start measuring time from any part of your code.
import TimeMeasurer from '@universal-packages/time-measurer'
async function getAll() {
const measurer = new TimeMeasurer()
measurer.start()
const data = await myDB.getAllRecords()
const measurement = measurer.finish()
console.log('All records - ', measurement.toString())
}
getAll()
// > All records - 2.23ms
A Measurement
object is the time representation after a measure, it provides the interface to express time as a formatted string or even as a date object.
Get the time representation as a string, this function takes one param TimeFormat
, that can be one of Condensed
, Human
, Expressive
, default: Human
.
measurement.toString()
measurement.toString('Condensed')
measurement.toString('Human')
measurement.toString('Expressive')
You will get someting like
02hrs 35min 51.235sec
02:35:51.235
02hrs 35min 51.235sec
02 Hours, 35 Minutes, and 51.235 Seconds
It will take into account parts of the representation that are not contributing to the time, like if the measurement only took seconds, minutes and hours will not be included.
51.235sec
51.235
51.235sec
51.235 Seconds
Get the time representation as a date object this can be helpful if you want to use the Date
api to format or do whatever with the date.
measurement.toDate()
A more simple way to use the time measurer API is by importing just the start
and finish
functions, the only disadvantage here is that you can only measure one thing at a time, unlike TimeMeasurer
that can be instantiated multiple times and measurer several things useful when you have a lot of async tasks running.
import { start, finish } from '@universal-packages/time-measurer'
async function getAll() {
start()
const data = await myDB.getAllRecords()
const measurement = finish()
console.log('All records - ', measurement.toString())
}
getAll()
// > All records - 2.23ms
Time measurer ships with a convenient sleep function that takes a single parameter time
in milliseconds, internally it is just a promise with a timeout that resolves it.
import TimeMeasurer, { sleep } from '@universal-packages/time-measurer'
async function waitable() {
TimeMeasurer.sleep(1000)
sleep(2000)
}
Time Measurer is developed in TypeScript and shipped fully typed.
Development of Time Measurer happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving Recoil.
FAQs
Utility to measure routines times with precision
The npm package @universal-packages/time-measurer receives a total of 11,448 weekly downloads. As such, @universal-packages/time-measurer popularity was classified as popular.
We found that @universal-packages/time-measurer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.