alexozer / flitter

A LiveSplit-inspired speedrunning split timer for Linux/macOS terminal. Supports global hotkeys.
MIT License
133 stars 11 forks source link

Use Core more fully #11

Closed lezed1 closed 2 years ago

lezed1 commented 5 years ago

I added benchmarking in a crude way, but I think it's enough to show it's not that slow at all. The test includes setting up everything and printing/drawing the first frame. Here are the benchmarks for 10 splits.

Original:

┌───────────────────────┬─────────────┬─────────┬──────────┬──────────┬────────────┐
│ Name                  │    Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────┼─────────────┼─────────┼──────────┼──────────┼────────────┤
│ [bench/basic.ml] loop │ 80_499.89ns │ 607.03w │  695.99w │  181.99w │    100.00% │
│ [bench/basic.ml] test │      2.51ns │         │          │          │            │
└───────────────────────┴─────────────┴─────────┴──────────┴──────────┴────────────┘

Updated:

┌───────────────────────┬─────────────┬─────────┬──────────┬──────────┬────────────┐
│ Name                  │    Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────┼─────────────┼─────────┼──────────┼──────────┼────────────┤
│ [bench/basic.ml] loop │ 78_793.66ns │ 607.03w │  697.20w │  183.20w │    100.00% │
│ [bench/basic.ml] test │      2.43ns │         │          │          │            │
└───────────────────────┴─────────────┴─────────┴──────────┴──────────┴────────────┘

And for 1000 splits.

Original:

┌───────────────────────┬─────────────┬─────────┬──────────┬──────────┬────────────┐
│ Name                  │    Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────┼─────────────┼─────────┼──────────┼──────────┼────────────┤
│ [bench/basic.ml] loop │ 81_635.56ns │ 607.03w │  696.63w │  182.63w │    100.00% │
│ [bench/basic.ml] test │      2.51ns │         │          │          │            │
└───────────────────────┴─────────────┴─────────┴──────────┴──────────┴────────────┘

Updated:

┌───────────────────────┬─────────────┬─────────┬──────────┬──────────┬────────────┐
│ Name                  │    Time/Run │ mWd/Run │ mjWd/Run │ Prom/Run │ Percentage │
├───────────────────────┼─────────────┼─────────┼──────────┼──────────┼────────────┤
│ [bench/basic.ml] loop │ 79_282.78ns │ 607.03w │  697.20w │  183.20w │    100.00% │
│ [bench/basic.ml] test │      2.50ns │         │          │          │            │
└───────────────────────┴─────────────┴─────────┴──────────┴──────────┴────────────┘

The time difference is minor and each speed is well below the time needed for 1 frame (over 3 orders of magnitude lower and the benchmark includes a bunch of the startup too!). I'm confident this is fast enough to not worry at all about lists versus arrays. Feel free to test it on a larger number of splits, but I think 1000 is reasonable.