🚀 DAY 5 OF LAUNCH WEEK: Introducing Socket Firewall Enterprise.Learn more →
Socket
Book a DemoInstallSign in
Socket

@nelsongomes/ts-timeframe

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

@nelsongomes/ts-timeframe

Benchmark framework to collect code time metrics and excel in speed

unpublished
Source
npmnpm
Version
0.1.0
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Ts-timeframe.js v0.1.0

A reliable, lightweight, fine grained javascript library for high performance backend applications, built with Typescript and with 100% code coverage. It allows to measure individual events, but also to trigger callbacks according to defined rules.

Installation

Using npm:

$ npm i --save ts-timeframe

Simple usage example in typescript (constructor default is ms, 3 decimals):

import { Timeline } from "ts-timeframe";

// we start timeline
const timeline = new Timeline();

const event = timeline.startEvent();
// we do something
event.end();

timeline.end();

// get timeline duration
timeline.duration();

More complex usage:

import { Timeline, ITimelineUnit } from "ts-timeframe";

// timeline in microseconds, no decimals in precision
const timeline = new Timeline(ITimelineUnit.Microseconds, 0);

// label the event and add info for the callback to receive
const event = timeline.startEvent(["database", "delete"], {
  table: "x",
  server: "1"
});
// we do something
event.end();

timeline.end();

// get timeline duration
timeline.duration();
timeline.generateAnalyticInfo();

Sample output:

***** Analytic Information for this Timeline *****
Total events: 1
Grand duration: 299.99900 µs
Events duration: 100.00000 µs

***** Event Detail for this Timeline *****
#1: [started: 99.99900 µs, duration: 100.00000 µs, labels: database,mysql]

Changing defaults (callable once) and adding slowEvents rules:

import { Timeline } from "ts-timeframe";

Timeline.init({
  unit: ITimelineUnit.Milliseconds, // default unit for constructor class
  precision: 5, // decimals for unit

  // a list of event rules to trigger a callback
  // if they take longer than duration and label matches
  // with this you can log queries or requests,
  // all callbacks are called after timeline end.
  slowEvents: [
    {
      callback: () => {
        /* some action */
      },
      rule: {
        duration: 100,
        matchAnylabel: ['database'],
        message: 'Database too slow'
      }
    },
    {
      callback: () => {
        /* some action */
      },
      rule: {
        duration: 3000,
        matchAnylabel: ['api'],
        message: 'Api calls too slow'
      }
    }
  ]
});

(...)

FAQs

Package last updated on 21 Feb 2020

Did you know?

Socket

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.

Install

Related posts