-
Notifications
You must be signed in to change notification settings - Fork 3
/
testcache.py
41 lines (34 loc) · 1.43 KB
/
testcache.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import sys
import os
from curtsies.fmtfuncs import blue, red, bold, on_red
from curtsies.window import Window
from curtsies.terminal import Terminal
import time
if __name__ == '__main__':
print(blue('hey') + ' ' + red('there') + ' ' + red(bold('you')))
n = int(sys.argv[1]) if len(sys.argv) > 1 else 100
with Terminal(sys.stdin, sys.stdout) as tc:
with Window(tc) as t:
rows, columns = t.tc.get_screen_size()
t0 = time.time()
for i in range(n):
a = [blue(on_red('qwertyuiop'[i%10]*columns)) for _ in range(rows)]
t.render_to_terminal(a)
t1 = time.time()
t2 = time.time()
for i in range(n):
a = [blue(on_red('q'[i%1]*columns)) for _ in range(rows)]
t.render_to_terminal(a)
t3 = time.time()
t4 = time.time()
a = [blue(on_red('q'*columns)) for _ in range(rows)]
arrays = []
for i in range(n):
a[i // columns] = a[i // columns].setitem(i % columns, 'x')
arrays.append([fs.copy() for fs in a])
for i in range(n):
t.render_to_terminal(arrays[i])
t5 = time.time()
s = """ all different: %f\tall identical: %f\tchange on character %f\t%d iterations\t""" % (t1 - t0, t3 - t2, t5 - t4, n)
os.system('echo `git log --pretty=oneline -n 1` '+s+' >> times.txt')
print(s)