47 lines
1 KiB
Python
47 lines
1 KiB
Python
"""Benchmark update throughput: plain str vs TermStr (RGB & xterm)."""
|
|
|
|
import textgrid
|
|
import termstr
|
|
import time
|
|
|
|
ROWS = 40
|
|
COLS = 100
|
|
SECONDS = 5
|
|
|
|
|
|
def main():
|
|
tg = textgrid.TextGrid(ROWS, COLS)
|
|
time.sleep(0.3)
|
|
|
|
plain = ["A" * COLS] * ROWS
|
|
|
|
style_rgb = termstr.CharStyle(fg_color=(255, 80, 80))
|
|
term_rgb = [termstr.TermStr("A" * COLS, style_rgb)] * ROWS
|
|
|
|
style_xterm = termstr.CharStyle(fg_color=9)
|
|
term_xterm = [termstr.TermStr("A" * COLS, style_xterm)] * ROWS
|
|
|
|
for label, data in [
|
|
("plain str ", plain),
|
|
("TermStr RGB ", term_rgb),
|
|
("TermStr xterm ", term_xterm),
|
|
]:
|
|
for _ in range(10):
|
|
tg.update(data)
|
|
|
|
n = 0
|
|
t0 = time.monotonic()
|
|
while True:
|
|
tg.update(data)
|
|
n += 1
|
|
elapsed = time.monotonic() - t0
|
|
if elapsed >= SECONDS:
|
|
break
|
|
|
|
print(f" {label} {n / elapsed:>8.0f} updates/s ({n} in {elapsed:.1f}s)")
|
|
|
|
tg.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|