Skip to content

Xomps/time-it

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple function timing, by default logs to the console (e.g. Generate API: 5.877s)

Install

npm install github:xomps/time-it

API / Examples

  import time from 'time-it'
  import { generateKey, encrypt } from './lib'

  const { returnVal: key } = await time('Generate key', generateKey) // -> Generate key: 12.735s

  const { returnVal: encryptedData, ms } = await time('Encrypt', () => encrypt(key), false)
  console.log(ms) // -> 55468

Types

  function timeIt(
    label: string,        // label used for console.log
    fn: () => any,        // function to time
    log?: boolean = true  // log to console
  ): Promise<{
    returnVal: any;       // return value of fn
    ms: number;           // raw milliseconds
    asString: string;     // time formated to seconds
  }>