npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

time-exec

v1.0.3

Published

Checks the execution time of functions.

Downloads

8

Readme

Time-exec

Checks the execution time of functions.

Installing

npm install time-exec

Start - finish

We can check the execution time of any code from calling the start method to calling the finish method.

import { Timer } from 'time-exec';

function sum(first, last) {
    let sum = 0;
    for (let i = first; i < last; i++) {
        sum += i
    }
    return sum;
}

let timer = new Timer();
timer.start();
sum(1, 10000);
timer.finish();
console.log("The function sum was completed in " + timer.getTimeExec() + "ms")

If you have started timer and haven`t finish, then getTimeExec() returns 0.

Asynchronous functions

Start-finish works with asynchronous functions.

import { Timer } from 'time-exec';

let timer = new Timer();
timer.start();
setTimeout(() => { 
    sum(1, 10000);
    timer.finish() }, 1000);
setTimeout(() => { 
    console.log("The function with timeout was completed in " + timer.getTimeExec() + "ms") 
    }, 2000);

Check the execution time of the function.

We can check the execution time of the function.

import { Timer } from 'time-exec';

let timer = new Timer();
timer.funcTimeExec(sum, 1, 10000);
console.log("The function sum was completed in " + timer.getTimeExec() + "ms");

Check the execution time of several function calls.

We can check the execution time of several function calls.

import { Timer } from 'time-exec';

let timer = new Timer();
timer.funcRepeatTimeExec(sum, 100, 1, 10000);
console.log("The function sum was completed 100 times in " + timer.getTimeExec() + "ms");

Check the average execution time of a function over several calls.

We can check the average execution time of a function over several calls.

let timer = new Timer();
timer.funcAverageTimeExec(sum, 100, 1, 10000);
console.log("For 100 times, the function was completed in an average of " + timer.getTimeExec() + "ms");

Documentation

You can find documentation in ./node_modules/time-exec/docs You can delete documentation for save memory.

System requirements

I have tested this package only:

  1. Google chrome 109.0.5414.168
  2. node js 20.12.2

I think that may be errors on some old node versions.

License

MIT