Skip to content

Instantly share code, notes, and snippets.

@janlelis
Last active January 9, 2024 11:12
Show Gist options
  • Save janlelis/91413b9295c81ee873dc to your computer and use it in GitHub Desktop.
Save janlelis/91413b9295c81ee873dc to your computer and use it in GitHub Desktop.
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 :)

@ixti
Copy link

ixti commented Jan 6, 2024

On Ruby 3.3 with latest gem versions

# TERMINAL ANSI COLORS BENCHMARK

  ruby: 3.3.0
  paint: 2.3.0
  rainbow: 3.1.1
  term/ansicolor 1.7.1
  pastel 0.8.0
  ansi 1.5.0
  hansi 0.2.1

## ONLY FOREGROUND COLOR

ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]
Warming up --------------------------------------
               paint   370.390k i/100ms
    paint w/ nesting   299.070k i/100ms
             rainbow    46.246k i/100ms
      term/ansicolor    18.406k i/100ms
              pastel    39.146k i/100ms
                ansi   236.789k i/100ms
               hansi    24.617k i/100ms
Calculating -------------------------------------
               paint      3.596M (± 0.8%) i/s -     18.149M in   5.046661s
    paint w/ nesting      2.933M (± 1.2%) i/s -     14.954M in   5.099293s
             rainbow    456.926k (± 3.6%) i/s -      2.312M in   5.067824s
      term/ansicolor    179.070k (± 3.3%) i/s -    901.894k in   5.042111s
              pastel    378.140k (± 2.8%) i/s -      1.918M in   5.076893s
                ansi      2.332M (± 2.3%) i/s -     11.839M in   5.080143s
               hansi    242.015k (± 1.8%) i/s -      1.231M in   5.087646s

Comparison:
               paint:  3596486.1 i/s
    paint w/ nesting:  2932872.0 i/s - 1.23x  slower
                ansi:  2331831.6 i/s - 1.54x  slower
             rainbow:   456925.9 i/s - 7.87x  slower
              pastel:   378140.5 i/s - 9.51x  slower
               hansi:   242014.9 i/s - 14.86x  slower
      term/ansicolor:   179070.1 i/s - 20.08x  slower


## FOREGROUND + BACKGROUND COLOR

ruby 3.3.0 (2023-12-25 revision 5124f9ac75) [x86_64-linux]
Warming up --------------------------------------
               paint   155.370k i/100ms
    paint w/ nesting   147.637k i/100ms
             rainbow    22.248k i/100ms
      term/ansicolor     8.547k i/100ms
              pastel    30.476k i/100ms
Calculating -------------------------------------
               paint      1.591M (± 0.8%) i/s -      8.079M in   5.077775s
    paint w/ nesting      1.477M (± 3.8%) i/s -      7.382M in   5.006203s
             rainbow    219.552k (± 6.4%) i/s -      1.112M in   5.089242s
      term/ansicolor     80.368k (± 6.8%) i/s -    401.709k in   5.024147s
              pastel    309.032k (± 2.6%) i/s -      1.554M in   5.033123s

Comparison:
               paint:  1591197.4 i/s
    paint w/ nesting:  1476814.6 i/s - 1.08x  slower
              pastel:   309032.4 i/s - 5.15x  slower
             rainbow:   219552.3 i/s - 7.25x  slower
      term/ansicolor:    80368.5 i/s - 19.80x  slower

@janlelis
Copy link
Author

janlelis commented Jan 9, 2024

@ixti Thanks!

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