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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@kalpeshlambade/time-estimator

v1.0.1

Published

A lightweight library to estimate remaining execution time for processes

Downloads

13

Readme

TimeEstimator

TimeEstimator is a utility class for estimating the remaining time for a set of operations based on the median execution time of previous iterations. It is particularly useful when performing a task that involves processing multiple items and you need to log the estimated remaining time after each operation.

Installation

To use the TimeEstimator class, you can either copy it into your project or install it as a module if you plan to publish it to a package registry.

npm install @kalpeshlambade/time-estimator

Usage

Example

import { TimeEstimator } from 'time-estimator';

const totalItems = 100; // Total number of items to process
const timeEstimator = new TimeEstimator(totalItems);

// For each iteration, use recordStart(), recordEnd(), and logTimeRemaining
for (let i = 0; i < totalItems; i++) {
  timeEstimator.recordStart();

  // Your processing logic here (e.g., data processing, API calls, etc.)

  timeEstimator.recordEnd();
  timeEstimator.logTimeRemaining(i);
}

Class Methods

constructor(totalItems: number)

Creates a new TimeEstimator instance with the given number of items to process.

  • Arguments:

    • totalItems (number): Total number of items you need to process. Must be a positive number.
  • Throws: If totalItems is not a positive number.

recordStart(): void

Records the start time of the current iteration. Should be called before starting the task.

recordEnd(): void

Records the end time of the current iteration. Should be called after finishing the task.

logTimeRemaining(iteration: number): void

Logs the estimated remaining time for the remaining iterations, based on the median execution time of previous iterations.

  • Arguments:

    • iteration (number): The current iteration number (should be between 0 and totalItems - 1).
  • Throws: If the iteration number is not within the valid range (0 to totalItems - 1).

Internal Helper Methods

calculateCentralValue(): number

Calculates the median of all recorded execution times. This is used to estimate the time remaining for subsequent iterations.

outputLogs(median: number, iteration: number): void

Outputs the logs displaying the estimated time remaining in both minutes and seconds, as well as in milliseconds.

Error Handling

  • If the totalItems parameter is not a positive number, an error will be thrown during instantiation.
  • If the iteration passed to logTimeRemaining is not valid (i.e., outside the range from 0 to totalItems - 1), an error will be thrown.

Example Output

For each iteration, the class will log an output similar to this:

----------------------------------------------
Iteration : 5
Estimate time : 15 minutes & 30 seconds
Estimate time milliseconds : 930000
----------------------------------------------
  • Iteration: The current iteration number (starting from 1).
  • Estimate time: The estimated time remaining for the remaining items, formatted in minutes and seconds.
  • Estimate time milliseconds: The estimated time in milliseconds.

Contributing

Feel free to submit issues or pull requests if you have any improvements or bug fixes!

License

This project is licensed under the MIT License - see the LICENSE file for details.