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

lap

v0.3.1

Published

Performance testing library

Downloads

12

Readme

lap

JavaScript performance testing library for the browser or server

API

Methods

  • lap.time(laps, racers)
  • lap.speed(laps, racers)
  • lap.timestamp()

Parameters

  • laps refers to number of laps to run (positive integer)
  • racers refers to function(s) to race (array or single function)

Usage tips

  • Use JavaScript exponential notation like 1e3 (rather than 1000) for expressing large numbers
  • Accurate results require many laps. The ideal amount depends on how complex the racers are:
    • Infinity speeds and 0 times both indicate inadequate laps
    • Results taking too long indicates excessive laps. Use less laps or use the .async syntax

lap.time(laps, racers)

  • Time how long it takes each racer to run the given number of laps
  • @return array of times measured in milliseconds
.time example
lap.time(1e5, [
  function() { document.getElementById('example') },
  function() { document.querySelector('#example') },
  function() { document.querySelectorAll('#example')[0] }
]) // => [40.000000000873115, 44.99999999825377, 116.00000000180444]

lap.speed(laps, racers)

  • Estimate each racer's average speed over a course of laps
  • @return array of speeds measured in operations per second
.speed example
lap.speed(1e5, [
  function() { document.getElementById('example') },
  function() { document.querySelector('#example') },
  function() { document.querySelectorAll('#example')[0] }
]) // => [2500000.0004001777, 2222222.2219491494, 884955.7522315352]

lap.timestamp()

  • Get a hi-resolution timestamp
  • @return number measured in milliseconds
.timestamp example
lap.timestamp() // => 1610.000000000582

.async

  • Methods are callable .async with the same arguments plus a (err, result) callback
  • @return undefined
.async syntax
  • lap.time.async(laps, racers, callback)
  • lap.speed.async(laps, racers, callback)
  • lap.timestamp.async(callback)
.async example
lap.time.async(1e5, function() {
  [].concat([0, 1, 2, 3])
}, function(err, result) {
  err || console.log(result[0] + ' ms')
}) // => undefined

.sync

.sync methods are included for expressiveness but these are just aliases. lap.time === lap.time.sync etc.

.sync example
lap.time.sync(1e5, [
  function() { document.getElementById('example') },
  function() { document.querySelector('#example') },
  function() { document.querySelectorAll('#example')[0] }
]) // => [40.000000000873115, 45.99999999481952, 115.00000000523869]

Compatibility

Works...everywhere! Tested in node, Chrome, FF, Opera, IE8

Contribute

$ npm start
$ npm test