Created
February 24, 2024 18:03
-
-
Save fabiospampinato/5b1a953d09a01102dd1866ece7cb26ea to your computer and use it in GitHub Desktop.
string-width_slowness_bench.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* IMPORT */ | |
import benchmark from 'benchloop'; | |
import stringWidth from 'string-width'; | |
// import fastStringWidth from '../dist/index.js'; | |
/* HELPERS */ | |
const IMPLEMENTATIONS = [ | |
// [Bun.stringWidth, 'bun'], | |
[stringWidth, 'string-width'], | |
// [fastStringWidth, 'fast-string-width'] | |
]; | |
const INPUTS = [ | |
['hello', 'ascii'], | |
['\x1b[31mhello', 'ascii+ansi'], | |
['hello😀', 'ascii+emoji'], | |
['\x1b[31m😀😀', 'ansi+emoji'], | |
['😀hello😀\x1b[31m😀😀😀', 'ascii+ansi+emoji'] | |
]; | |
const REPETITIONS = [1, 10, 100, 1_000, 5_000, 25_000]; | |
/* MAIN */ | |
benchmark.config ({ | |
iterations: 1 | |
}); | |
for ( const [implementation, implementationName] of IMPLEMENTATIONS ) { | |
benchmark.group ( implementationName, () => { | |
for ( const [input, inputName] of INPUTS ) { | |
for ( const repetitions of REPETITIONS ) { | |
const string = input.repeat ( repetitions ); | |
benchmark ({ | |
name: `${inputName}x${repetitions}`, | |
fn: () => { | |
implementation ( string ); | |
} | |
}); | |
} | |
} | |
}); | |
} | |
benchmark.summary (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment