8000 replace `ms` w/ `@lukeed/ms` by SukkaW · Pull Request #230 · dimdenGD/ultimate-express · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

replace ms w/ @lukeed/ms #230

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

replace ms w/ @lukeed/ms #230

wants to merge 1 commit into from

Conversation

SukkaW
Copy link
@SukkaW SukkaW commented Jun 9, 2025

@lukeed/ms is a fork of Vercel's ms and improves the performance by 20%, yet the package is way smaller. That PR is never merged by Vercel til this day, and lukeed decides to maintain his fork instead.

This PR replaces ms with/ @lukeed/ms.

@cesco69
Copy link
Contributor
cesco69 commented Jun 9, 2025

Test fails...

TypeError: ms is not a function

Try to change this

const ms = require('@lukeed/ms');

into this

const { parse } = require('@lukeed/ms');
const ms = parse;

@SukkaW
Copy link
Author
SukkaW commented Jun 9, 2025

Test fails...

TypeError: ms is not a function

Try to change this

const ms = require('@lukeed/ms');

into this

const { parse } = require('@lukeed/ms');
const ms = parse;

Oops, I thought it was a drop-in replacement.

@SukkaW
Copy link
Author
SukkaW commented Jun 9, 2025

Fixed in d044f7b (#230)

cc @cesco69

@SukkaW
Copy link
Author
SukkaW commented Jun 10, 2025

cc @dimdenGD

@jimmyolo
Copy link
Contributor

is it still extra performant in node v20 / v22?

const { run, bench, summary } = require('mitata');
const msVercel = require('ms');
const msLukeed = require('@lukeed/ms');
const msItty = require('itty-time');
const prettyMs = require('pretty-ms').default;
const toMs = require('@sindresorhus/to-milliseconds').default;
const humanizeDuration = require('humanize-duration');

summary(() => {
  bench('vercel/ms: ms->string', () => {
    msVercel(60000);
  });
  bench('lukeed/ms: ms->string', () => {
    msLukeed.format(60000);
  });
  bench('itty-time: ms->string', () => {
    msItty.ms(60000);
  });
  bench('pretty-ms: ms->string', () => {
    prettyMs(60000, { verbose: true });
  });
  bench('humanize-duration: ms->string', () => {
    humanizeDuration(60000);
  });
});

summary(() => {
  bench('vercel/ms: string->ms', () => {
    msVercel('1 minute');
  });
  bench('lukeed/ms: string->ms', () => {
    msLukeed.parse('1 minute');
  });
  bench('itty-time: string->ms', () => {
    msItty.ms('1 minute');
  });
  bench('to-milliseconds: object->ms', () => {
    toMs({minutes: 1});
  });
});

run({ gc: 'inner' })
cpu: AMD Ryzen AI 9 HX 370 w/ Radeon 890M
runtime: node 22.16.0 (x64-linux)

benchmark                    avg (min … max) p75 / p99    (min … top 1%)
-------------------------------------------- -------------------------------
vercel/ms: ms->string           1.40 ns/iter   1.39 ns           █          
                        (1.26 ns … 14.67 ns)   1.50 ns           █▃         
                     (  0.10  b … 113.19  b)   0.11  b ▁▁▁▁▁▁▁▁▁▁██▁▁▁▁▁▁▁▁▁

lukeed/ms: ms->string           1.34 ns/iter   1.33 ns    █                 
                        (1.27 ns … 18.52 ns)   1.63 ns    █                 
                     (  0.11  b …  53.49  b)   0.12  b ▁▁▂█▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

itty-time: ms->string         778.52 ps/iter 772.71 ps      █               
                      (733.64 ps … 28.51 ns) 880.37 ps      █               
                     (  0.11  b …  18.13  b)   0.11  b ▁▁▁▁▃█▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁

pretty-ms: ms->string         180.36 ns/iter 183.18 ns   █                  
                     (173.58 ns … 308.03 ns) 203.30 ns  ██                  
                     (496.42  b …   1.11 kb) 688.60  b ▂███▄▃▃▃▂▄▄▄▂▂▂▁▁▁▁▁▁

humanize-duration: ms->string 330.33 ns/iter 332.60 ns   ▅█                 
                     (321.84 ns … 410.51 ns) 354.93 ns  ▃███                
                     (459.12  b …   1.41 kb) 825.48  b ▃█████▃▃▂▆▇▅▃▃▂▂▁▁▂▁▁

summary
  itty-time: ms->string
   1.72x faster than lukeed/ms: ms->string
   1.79x faster than vercel/ms: ms->string
   231.68x faster than pretty-ms: ms->string
   424.31x faster than humanize-duration: ms->string

-------------------------------------------- -------------------------------
vercel/ms: string->ms          50.09 ns/iter  49.65 ns     █                
                      (45.15 ns … 129.74 ns)  64.62 ns    ▆█                
                     ( 19.07  b … 450.14  b) 251.42  b ▁▂▂███▃▂▁▁▁▁▁▁▁▁▂▂▂▁▁

lukeed/ms: string->ms          44.18 ns/iter  43.59 ns  █                   
                       (41.98 ns … 85.26 ns)  59.30 ns  █▃                  
                     ( 68.05  b … 286.29  b) 198.63  b ▃██▃▁▁▁▁▁▁▁▁▁▁▁▁▁▂▁▁▁

itty-time: string->ms          49.10 ns/iter  48.53 ns  █▂                  
                      (45.58 ns … 160.23 ns)  73.02 ns  ██                  
                     (100.82  b … 453.51  b) 200.28  b ▁██▇▁▁▁▁▁▁▂▂▁▁▁▁▁▁▁▁▁

to-milliseconds: object->ms    57.57 ns/iter  57.05 ns     █                
                       (52.90 ns … 99.20 ns)  73.05 ns     █                
                     ( 60.86  b … 542.02  b) 171.56  b ▁▁▁▆█▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

summary
  lukeed/ms: string->ms
   1.11x faster than itty-time: string->ms
   1.13x faster than vercel/ms: string->ms
   1.3x faster than to-milliseconds: object->ms

@SukkaW
Copy link
Author
SukkaW commented Jun 11, 2025

is it still extra performant in node v20 / v22?

summary
  lukeed/ms: string->ms
   1.11x faster than itty-time: string->ms
   1.13x faster than vercel/ms: string->ms
   1.3x faster than to-milliseconds: object->ms

Well, with your own benchmark, it shows @lukeed/ms is 13% faster than the vercel's ms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0