sharkdp / pastel

A command-line tool to generate, analyze, convert and manipulate colors
Apache License 2.0
5.04k stars 97 forks source link

Move regex compiles into lazy_static block to speed up parsing #40

Closed sharkdp closed 5 years ago

sharkdp commented 5 years ago

Reading input is currently really slow:

▶ pastel random -n 1000 > colors
▶ hyperfine 'pastel format hex < colors'
Benchmark #1: pastel format hex < colors
  Time (mean ± σ):     313.8 ms ±   5.9 ms    [User: 309.8 ms, System: 3.5 ms]
  Range (min … max):   307.8 ms … 327.9 ms    10 runs

The main reason is that we compile the regexes in each iteration: image

sharkdp commented 5 years ago

After the fix:

Benchmark #1: pastel format hex < colors
  Time (mean ± σ):       5.5 ms ±   1.3 ms    [User: 4.0 ms, System: 1.7 ms]
  Range (min … max):     3.3 ms …  10.5 ms    476 runs