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

@benoitzohar/replx

v0.3.1

Published

REPL tool on steroids

Downloads

3

Readme

REPLx - A REPL CLI tool on steroids

npm version Build Status Codacy Badge

"Read-Eval-Print-Loop-times" allows you to run a Javascript code with node and monitor the execution time for as many executions as you want.

Installation

You may want to install replx globally to be able to use it wherever you want:

npm i -g @benoitzohar/replx

Usage

replx [options] <source> [times]

Run an inline script:

$ replx "console.log('hello')" 3
 hello
 hello
 hello
 [Inline code] 1.312974ms

or load a file:

$ replx myfile.js
 oh hello
 [myfile.js] 1.3433752ms

You can watch for file changes and rerun replx everytime:

$ replx --watch myfile.js

or

$ replx -w myfile.js

Comparison

To compare multiple functions, you can create a file that exports as many function as you'd like and replx will compare the time for you. For example:

const base = "Lorem ipsum dolor sit amet, mea dolor placerat consectetuer ut";

module.exports.A = () => {
  const res = [];
  base.split().forEach(c => res.push(c.toUpperCase()));
  return res;
};

module.exports.B = () => {
  const res = base.split().map(c => c.toUpperCase());
  return res;
};

Run multiple times

Of course, one run is not enough to determine which function is faster, so you can easily tell replx to run you code multiple time. For example, here we will run the code for each functions in the file 1000000 times:

$ replx myfile.js 1000000

Note that the returned value of each function will not be logged if you run the code multiple times.

Create

You can create an empty file automatically if it doesn't exist:

$ replx --create myfile.js

or

$ replx -c myfile.js

Since the file will be empty by default, we suggest that you use -c along with -w so you can use replx -c -w myfile.js and start measuring right away.

If you want to make a comparison, you can create a file with 2 exported functions:

$ replx --comparison myfile.js

or

$ replx -k myfile.js

Example

$ replx -k -w myfile.js 1000
[B] 0.08004ms
[A] 0.098599ms (1x slower)
---
[A] 0.086088ms
[B] 0.166884ms (2x slower)

This command will:

  • create the file myfile.js with 2 exports functions:
module.exports.A = () => {
  return "A";
};

module.exports.B = () => {
  return "B";
};
  • open it in your default IDE (based on the file extension)
  • run the code 1000 times for each function
  • compare the time between the two functions
  • watch for file change and re-run, etc.

Help

Use replx or replx -h for help.

Notes

For now, if you use replx as an inline script, be aware that the timing includes the cost of eval() at each loop. This means that the time to run displayed is not exactly the time to run your script.
In the same spirit, if you use a file, the cached cost of require() will be included.

However, using replx to compare the time-to-run of two different scripts will work as expected since the require cost will be the same in all the variants.

The run time can vary greatly between runs, we suggest that you run replx more than once to ensure the results are aligned.