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

perf: cache intl object #54

Merged
merged 1 commit into from Jan 22, 2024
Merged

Conversation

H4ad
Copy link
Contributor

@H4ad H4ad commented Jan 21, 2024

Inspired by https://twitter.com/jarredsumner/status/1749032292771942605

Before:

cpu: AMD Ryzen 9 5950X 16-Core Processor
runtime: node v20.7.0 (x64-linux)

benchmark                                    time (avg)             (min … max)       p75       p99      p995
------------------------------------------------------------------------------- -----------------------------
npm/string-width (ansi + emoji + ascii)   13.78 µs/iter     (11.2 µs … 1.24 ms)  11.74 µs  26.01 µs  28.73 µs
npm/string-width (ansi + emoji)            8.43 µs/iter      (8.09 µs … 9.2 µs)   8.65 µs    9.2 µs    9.2 µs
npm/string-width (ansi + ascii)           11.07 µs/iter     (9.27 µs … 3.05 ms)   9.87 µs  12.07 µs   13.8 µs

Now:

cpu: AMD Ryzen 9 5950X 16-Core Processor
runtime: node v20.7.0 (x64-linux)

benchmark                                    time (avg)             (min … max)       p75       p99      p995
------------------------------------------------------------------------------- -----------------------------
npm/string-width (ansi + emoji + ascii)    8.07 µs/iter   (7.08 µs … 397.88 µs)    7.4 µs   9.09 µs  11.83 µs
npm/string-width (ansi + emoji)            2.94 µs/iter     (2.82 µs … 3.34 µs)   2.99 µs   3.34 µs   3.34 µs
npm/string-width (ansi + ascii)            6.23 µs/iter     (6.18 µs … 6.32 µs)   6.24 µs   6.32 µs   6.32 µs

Benchmark:

import {bench, run} from 'mitata';
import npmStringWidth from './index.js';

bench('npm/string-width (ansi + emoji + ascii)', () => {
	npmStringWidth('hello there! 😀\u001B[31m😀😀');
});

bench('npm/string-width (ansi + emoji)', () => {
	npmStringWidth('😀\u001B[31m😀😀');
});

bench('npm/string-width (ansi + ascii)', () => {
	npmStringWidth('\u001B[31mhello there!');
});

run();

@sindresorhus sindresorhus merged commit b0dd0fa into sindresorhus:main Jan 22, 2024
2 checks passed
@H4ad H4ad deleted the perf/cache-intl branch January 22, 2024 10:13
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.

None yet

2 participants