All Projects → onury → perfy

onury / perfy

Licence: MIT license
A simple, light-weight NodeJS utility for measuring code execution in high-resolution real times.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to perfy

Modeltime
Modeltime unlocks time series forecast models and machine learning in one framework
Stars: ✭ 189 (+250%)
Mutual labels:  time
Blitz
Android Library: Set self-updating string with relative time in TextView (e.g. 5 minutes ago)
Stars: ✭ 217 (+301.85%)
Mutual labels:  time
ptera
Ptera is DateTime library for Deno
Stars: ✭ 62 (+14.81%)
Mutual labels:  time
Timelite
Why is it 5 AM? Isn't there something simple I can use to track what I'm doing with all this time?
Stars: ✭ 201 (+272.22%)
Mutual labels:  time
Twas
🕰 Tiny (280B) relative time string function (eg: "3 seconds ago")
Stars: ✭ 212 (+292.59%)
Mutual labels:  time
Server
self-hosted tag-based time tracking
Stars: ✭ 238 (+340.74%)
Mutual labels:  time
Rufus Scheduler
scheduler for Ruby (at, in, cron and every jobs)
Stars: ✭ 2,223 (+4016.67%)
Mutual labels:  time
iso8601
A fast ISO8601 date parser for Go
Stars: ✭ 122 (+125.93%)
Mutual labels:  time
Python Wechat Itchat
微信机器人,基于Python itchat接口功能实例展示:01-itchat获取微信好友或者微信群分享文章、02-itchat获取微信公众号文章、03-itchat监听微信公众号发送的文章、04 itchat监听微信群或好友撤回的消息、05 itchat获得微信好友信息以及表图对比、06 python打印出微信被删除好友、07 itchat自动回复好友、08 itchat微信好友个性签名词云图、09 itchat微信好友性别比例、10 微信群或微信好友撤回消息拦截、11 itchat微信群或好友之间转发消息
Stars: ✭ 216 (+300%)
Mutual labels:  time
nativescript-datetimepicker
Plugin with date and time picking fields
Stars: ✭ 26 (-51.85%)
Mutual labels:  time
Ansible Role Ntp
Ansible Role - NTP
Stars: ✭ 203 (+275.93%)
Mutual labels:  time
Sonataintlbundle
Symfony SonataIntlBundle
Stars: ✭ 212 (+292.59%)
Mutual labels:  time
Travel
Framework agnostic PHP package to control the time.
Stars: ✭ 251 (+364.81%)
Mutual labels:  time
Pytimeparse
A small Python module to parse various kinds of time expressions.
Stars: ✭ 195 (+261.11%)
Mutual labels:  time
SonataTimelineBundle
[Abandoned] Integrates SpyTimelineBundle into Sonata
Stars: ✭ 24 (-55.56%)
Mutual labels:  time
React Native Modal Datetime Picker
A React-Native datetime-picker for Android and iOS
Stars: ✭ 2,412 (+4366.67%)
Mutual labels:  time
Jiffy
Jiffy is a Flutter (Android, IOS and Web) date time package inspired by momentjs for parsing, manipulating, querying and formatting dates
Stars: ✭ 238 (+340.74%)
Mutual labels:  time
jodaTime
Format and Parse date and time with joda layout
Stars: ✭ 67 (+24.07%)
Mutual labels:  time
QuickTraceiOSLogger
A real time iOS log trace tool, view iOS log with pc web browser under local area network, which will automatically scroll like xcode. 一个实时的iOS日志跟踪工具,在局域网中使用 PC Web 浏览器查看 iOS 日志,它将像xcode一样自动滚动。
Stars: ✭ 16 (-70.37%)
Mutual labels:  time
Prayer Times Android Azan
Prayer + Time + Android + Kotlin + Azan + Library + timezone + islamic + salah + Library aiming to calculate prayer time with one line code , if you implement prayer time application , there is no need to do this headache again .
Stars: ✭ 251 (+364.81%)
Mutual labels:  time

perfy

npm release downloads license

A simple, light-weight Node.js utility for measuring code execution performance in high-resolution real times.

© 2021, Onur Yıldırım (@onury). MIT License.

Installation

    npm install perfy --save

Usage

var perfy = require('perfy');

Simple. Just call perfy.start('name') and the performance instance will be created and start time will be set until you call perfy.end('name') which returns a result object containing the high-res elapsed time information (and destroys the created instance).

perfy.start('loop-stuff');
// some heavy stuff here...
var result = perfy.end('loop-stuff');
console.log(result.time); // —> 1.459 (sec.)

... or you could:

perfy.exec('async-stuff', function (done) {
    // some heavy stuff here...
    var result = done();
    console.log(result.time); // —> 1.459 (sec.)
});

Documentation

.start(name [, autoDestroy])

Initializes a new performance instance with the given name; and marks the current high-resolution real time.

Parameters:

  • name String — Required. Unique name of the performance instance to be started. Setting an existing name will overwrite this item. Use .exists() method to check for existence.
  • autoDestroy Boolean — Optional. Default: true. Specifies whether this performance instance should be destroyed when .end() is called.

returns perfy

.end(name)

Ends the performance instance with the given name; and calculates the elapsed high-resolution real time. Note that if autoDestroy is not disabled when .start() is called; corresponding performance instance is immediately destroyed after returning the result.

Parameters:

  • name String — Required. Unique name of the performance instance to be ended.

returns Object — A result object with the following properties.

  • name String — Initialized name of the performance instance.
  • seconds Number — Seconds portion of the elapsed time. e.g. 1
  • milliseconds Number — Nanoseconds portion converted to milliseconds. 235.125283
  • nanoseconds Number — Nanoseconds portion of the elapsed time. e.g. 235125283
  • time Number — Float representation of full elapsed time in seconds. e.g. 1.235
  • fullSeconds Number — Alias of .time.
  • fullMilliseconds Number — Float representation of full elapsed time in milliseconds. e.g. 1235.125
  • fullNanoseconds Number — Float representation of full elapsed time in nanoseconds. e.g. 1235125283
  • summary String — Text summary shorthand for elapsed time.
  • startTime Number — UTC start time of the execution (low-resolution). e.g. 1533302465251
  • endTime Number — UTC end time of the execution (low-resolution). e.g. 1533302466486

.exec([name,] fn)

Initializes a new performance instance right before executing the given function, and automatically ends after the execution is done.

Parameters:

  • name String — Optional. Unique name of the performance instance. Set this if you want the keep the instance for later use (such as getting the result at a later time).
  • fn Function — Required. Function to be executed. This function is invoked with an optional done argument which is only required if you are running an asynchronous operation. You should omit the done argument if it's a synchronous operation.

returns Object|perfy — Returns a result object if running a synchronous operation (by omitting done).

function syncOp() {
    // sync operation
}
var result = perfy.exec(syncOp);

Otherwise (if asynchronous), immediately returns the perfy object and result will be returned by calling done() from within fn.

perfy.exec(function (done) {
    // a-sync operation
    var result = done();
    // perfy.count() === 0 // (auto-destroyed)
});

You can also save this performance instance by setting the name.

perfy.exec('async-op', function (done) {
    // a-sync operation
    done();
    perfy.exists('async-op'); // —> true (saved)
});

.result(name)

Gets the calculated result of the performance instance for the given name. To be used with non-destroyed, ended instances. If instance is not yet ended or does not exist at all, returns null.

Parameters:

  • name String — Required. Unique name of the performance instance.

returns Object — A result object (see .end() method).

.exists(name)

Specifies whether a performance instance exists with the given name. This method will return false for an item, if called after .end(name) is called since the instance is destroyed.

Parameters:

  • name String — Required. Name of the performance instance to be checked.

returns Boolean

.destroy(name)

Destroys the performance instance with the given name.

Parameters:

  • name String — Required. Name of the performance instance to be destroyed.

returns perfy

.destroyAll()

Destroys all existing performance instances.

returns perfy

.names()

Gets the names of existing performance instances.

returns Array

.count()

Gets the total number of existing performance instances.

returns Number

More Examples:

Basic:

perfy.start('metric-1');
var result1 = perfy.end('metric-1');
console.log(result1.seconds + ' sec, ' + result1.milliseconds.toFixed(3) + ' ms.');
// —> 1 sec, 234 ms.
// OR
console.log(result1.time + ' sec. ');
// —> 1.234 sec.

Auto-Destroy:

perfy.start('metric-2').count(); // —> 1 (metric-1 is already destroyed)
var result2 = perfy.end('metric-2');
perfy.count(); // —> 0 (metric-2 is also destroyed after .end() is called)

Keep the instance (disable autoDestroy):

perfy.start('metric-3', false);
perfy.end('metric-3').time; // —> 0.123
perfy.exists('metric-3'); // —> true

Destroy all:

perfy.destroyAll().count(); // —> 0

Save/exec async:

perfy
    .exec('async-op', function (done) {
        var result = done(); // === perfy.result('async-op')
        perfy.count(); // 1
    })
    .count(); // 0 (sync)

Changelog

  • v1.1.5 (2018-08-03)

    • Added .fullMilliseconds to result object. (PR #2 by @anho)
    • Added .fullNanoseconds and .fullSeconds (alias of .time) to result object.
    • (Dev) Removed grunt in favour of npm scripts.

  • v1.1.2 (2016-03-23)

    • Fixed time and summary padding issue. (PR #1 by @gunnarlium)
    • Other minor dev improvements.

  • v1.1.0 (2015-10-16)

    • Added .exec() convenience method.
    • .exists() will throw if no name is specified.

  • v1.0.1 (2015-10-12)

    • .result(name) will not throw (and return null) even if the perf-instance does not exist. It will throw if no name is specified.

  • v1.0.0 (2015-10-12)

    • First release.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].