The Wayback Machine - https://web.archive.org/web/20200916205714/https://github.com/vercel/ms/pull/120
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Break]: Golfing w/ Performance tuning #120

Open
wants to merge 6 commits into
base: master
from
Open

Conversation

@lukeed
Copy link

lukeed commented Jun 7, 2019

This PR adds a few things at once, sorry.

Breaking

  • Changed the 2nd param to be a boolean, toggling long-mode directly
    Of course this can be reverted, and I'm open to it, but don't foresee other options :)

Features

  • Multiple formats:

    • ESM (via module entry)
    • CommonJS (via main entry – unchanged)
    • UMD (via unpkg entry)
  • Made available on unpkg.com 🎉

Chores

  • Adds minimal benchmark suite
  • Attaches a light build tool (one of my own) to auto-build ^those formats
  • Includes prettier directly – was relying on global installation
  • Updates lint script

Here's a before-after of both the module size & the performance:

Running Node v10.13.0, no warmups

Before:

Filename                 Filesize  (gzip)
dist/index.js             1.41 kB  643 B
dist/index.mjs            1.41 kB  633 B
dist/index.min.js         1.56 kB  701 B


# string (short) -> number
  ms   x 11,828,412 ops/sec ±0.46% (92 runs sampled)

# string (long) -> number
  ms   x 5,803,783 ops/sec ±1.78% (96 runs sampled)

# number -> string (short)
  ms   x 76,444,334 ops/sec ±0.89% (96 runs sampled)

# number -> string (long)
  ms   x 33,576,081 ops/sec ±0.69% (93 runs sampled)

# Negative :: string (short) -> number
  ms   x 6,710,932 ops/sec ±1.41% (96 runs sampled)

# Negative :: string (long) -> number
  ms   x 5,944,477 ops/sec ±0.51% (95 runs sampled)

# Negative :: number -> string (short)
  ms   x 80,648,073 ops/sec ±0.22% (96 runs sampled)

# Negative :: number -> string (long)
  ms   x 32,387,825 ops/sec ±0.32% (98 runs sampled)

After

Filename                 Filesize  (gzip)
dist/index.js              948 B   521 B
dist/index.mjs             947 B   521 B
dist/index.min.js         1.10 kB  585 B


# string (short) -> number
  ms   x 13,121,298 ops/sec ±0.89% (93 runs sampled)

# string (long) -> number
  ms   x 6,087,008 ops/sec ±1.90% (93 runs sampled)

# number -> string (short)
  ms   x 77,564,203 ops/sec ±0.60% (91 runs sampled)

# number -> string (long)
  ms   x 46,140,236 ops/sec ±0.29% (93 runs sampled)

# Negative :: string (short) -> number
  ms   x 7,159,583 ops/sec ±0.30% (96 runs sampled)

# Negative :: string (long) -> number
  ms   x 6,152,167 ops/sec ±0.67% (94 runs sampled)

# Negative :: number -> string (short)
  ms   x 78,520,060 ops/sec ±0.64% (96 runs sampled)

# Negative :: number -> string (long)
  ms   x 45,736,035 ops/sec ±0.36% (95 runs sampled)

I have a few other versions locally, ranging from 569B to 487B, but they had different performance trade-offs. This 521B version feels like the best balance IMO.

@lukeed
Copy link
Author

lukeed commented Mar 14, 2020

Any feedback on this? Been a little while :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
1 participant
You can’t perform that action at this time.