Skip to content

Instantly share code, notes, and snippets.

@janlelis
Last active December 6, 2023 21:25
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Terminal Colors Benchmark: paint, rainbow, term/ansicolor, pastel, ansi, hansi

Benchmark Code: https://github.com/janlelis/paint/blob/main/benchmark.rb

# TERMINAL ANSI COLORS BENCHMARK

  ruby: 3.1.2
  paint: 2.3.0
  rainbow: 3.1.1
  term/ansicolor 1.7.1
  pastel 0.8.0
  ansi 1.5.0
  hansi 0.2.0

## ONLY FOREGROUND COLOR

Warming up --------------------------------------
               paint   155.853k i/100ms
    paint w/ nesting   172.652k i/100ms
             rainbow    25.968k i/100ms
      term/ansicolor     8.290k i/100ms
              pastel    18.861k i/100ms
                ansi   128.658k i/100ms
               hansi    13.906k i/100ms
Calculating -------------------------------------
               paint      1.767M (±11.8%) i/s -      8.728M in   5.026299s
    paint w/ nesting      1.447M (±12.1%) i/s -      7.251M in   5.094970s
             rainbow    229.656k (±10.6%) i/s -      1.143M in   5.034315s
      term/ansicolor     77.457k (±10.5%) i/s -    389.630k in   5.090180s
              pastel    176.023k (±10.5%) i/s -    886.467k in   5.095974s
                ansi      1.180M (±11.5%) i/s -      5.918M in   5.088074s
               hansi    128.376k (±11.7%) i/s -    639.676k in   5.056913s

Comparison:
               paint:  1766502.5 i/s
    paint w/ nesting:  1446663.0 i/s - same-ish: difference falls within error
                ansi:  1179723.2 i/s - 1.50x  (± 0.00) slower
             rainbow:   229655.6 i/s - 7.69x  (± 0.00) slower
              pastel:   176022.6 i/s - 10.04x  (± 0.00) slower
               hansi:   128375.5 i/s - 13.76x  (± 0.00) slower
      term/ansicolor:    77457.0 i/s - 22.81x  (± 0.00) slower


## FOREGROUND + BACKGROUND COLOR

Warming up --------------------------------------
               paint    77.983k i/100ms
    paint w/ nesting    90.350k i/100ms
             rainbow    13.089k i/100ms
      term/ansicolor     4.030k i/100ms
              pastel    14.714k i/100ms
Calculating -------------------------------------
               paint    937.918k (±10.4%) i/s -      4.679M in   5.051853s
    paint w/ nesting    816.568k (±12.3%) i/s -      4.066M in   5.061721s
             rainbow    120.536k (±11.3%) i/s -    602.094k in   5.064829s
      term/ansicolor     36.968k (±11.5%) i/s -    185.380k in   5.086501s
              pastel    136.340k (±10.1%) i/s -    676.844k in   5.017729s

Comparison:
               paint:   937918.2 i/s
    paint w/ nesting:   816568.2 i/s - same-ish: difference falls within error
              pastel:   136340.5 i/s - 6.88x  (± 0.00) slower
             rainbow:   120535.9 i/s - 7.78x  (± 0.00) slower
      term/ansicolor:    36967.6 i/s - 25.37x  (± 0.00) slower
@ssbarnea
Copy link

Quite interesting. I was looking for a way to benchmark my terminal itself in order to discover what is the source of slowness. Like comparing various iTerm builds with native Terminal.app on MacOS. Clearly these results are too detailed for my use case :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment