Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

perf-tester

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

perf-tester

An extremely small, zero dependency module to test performance of any of your code.

  • 1.0.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

perf-tester

An extremely small, zero dependency module to test performance of any of your code.

It uses it's own timer module to measure time taken which you can include separately in your project too.

All functions are promise based.

Usage

import { PerfTest } from 'perf-tester';
// const { PerfTest } = require('perf-tester');

const tester = new PerfTest();
  • measure( callback )

    Function to measure time taken for the callback function to execute. Works similar to console.time but results can be stored in a variable.

    callback - The callback function to test for.

    @returns - Time taken in miliseconds.

    (async () => {
    
        const result = await tester.measure(async () => {
            // some code to test
        });
        
    	// Returns time taken in ms for the code in callback to execute
        console.log(result + "ms");
    
    })();
    
  • testIteratively( iterations, callback )

    Executes the callback repeatetively for no. of iterations provided while measuring time taken by each callback and calculates average time taken for each.

    iterations - Number of iterations to test the callback. (Higher amount will take longer time)

    callback - The callback function to test for.

    @returns - [Object]

    {

    ​ avgTimeTaken : number // Average time taken in miliseconds,

    ​ tests : number [ ] // Array storing time taken by each test

    }

    (async () => {
    	
        // test the callback for 5 times
        const result = await tester.testIteratively(5, async () => {
            // some code to test
        });
        
    	// Returns average time taken and array of time taken by each test
        console.log(result);
    
    })();
    
  • batchTest ( iterations, array_of_callbacks )

    Similar to testIteratively but supports array of different callbacks to test for at once.

    iterations - Number of iterations to test the callback. (Higher amount will take longer time)

    array_of_callbacks - Array containing callbacks for whom testing should be done.

    @returns - Array containing results for each test.

    (async () => {
    
        // test the callbacks each time for 6 times
        const results = await tester.batchTest(6, [
            async () => {
                // some code to test
            },
            async () => {
                // some code to test
            }
        ]);
    
    	// Array of results for each callback
        console.log(results);
    
    })();
    

Any suggestions are warmly welcome.

Keywords

FAQs

Package last updated on 24 Sep 2021

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc