ur0 / lolcat

lolcat, now with fearless concurrency.
MIT License
99 stars 14 forks source link

So much for blazingly fast #25

Closed magnus-ISU closed 1 year ago

magnus-ISU commented 1 year ago

So I was quite pleased with myself that this implementation is much faster than other rust lolcats. But

hyperfine 'lolcat words' '/tmp/lolcrab/target/release/lolcrab words' /tmp/clolcat/clolcat\ words
Benchmark 1: lolcat words
  Time (mean ± σ):     110.0 ms ±  14.8 ms    [User: 89.9 ms, System: 18.7 ms]
  Range (min … max):    87.6 ms … 135.3 ms    23 runs

Benchmark 2: /tmp/lolcrab/target/release/lolcrab words
  Time (mean ± σ):     294.6 ms ±  12.0 ms    [User: 258.1 ms, System: 35.5 ms]
  Range (min … max):   280.0 ms … 310.7 ms    10 runs

Benchmark 3: /tmp/clolcat/clolcat words
  Time (mean ± σ):       1.1 ms ±   0.4 ms    [User: 0.4 ms, System: 0.9 ms]
  Range (min … max):     0.0 ms …   3.1 ms    1748 runs

Summary
  '/tmp/clolcat/clolcat words' ran
  103.45 ± 43.90 times faster than 'lolcat words'
  277.00 ± 112.04 times faster than '/tmp/lolcrab/target/release/lolcrab words'

That's not good. We can probably do a lot better. clolcat does not handle any escape sequences and so there are reasons to prefer going slower. But they're probably doing something quite clever which, especially when printing files and not stdin, I want to look into.

magnus-ISU commented 1 year ago

Wait I'm an idiot. I think clolcat is detecting that hyperfine is rerouting its stdout and then not doing anything. clolcat|cat isn't colored and is much faster. Using time manually gives both programs taking about the same, lolcat 700ms and clolcat 600ms.