summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2023-12-27 22:09:27 +0000
committerdavidovski <david@davidovski.xyz>2023-12-27 22:09:27 +0000
commit17dbc958104165cc0ed8acfd55137065f4fdb816 (patch)
tree6579182cfa3d995338a9d5f0fbdf131eccd30fd2
parenta35613e0558af8dd0b6fa158272f78005946eba2 (diff)
track performance of frames
-rwxr-xr-xtypr.sh36
1 files changed, 25 insertions, 11 deletions
diff --git a/typr.sh b/typr.sh
index 61f29c3..4517941 100755
--- a/typr.sh
+++ b/typr.sh
@@ -44,18 +44,24 @@ typr_draw_text () {
e="$entered_text"
lt=""
while [ "$t" ] ; do
- lt=$ct
- ct=${t%${t#?}}
- ce=${e%${e#?}}
+ lt="$ct"
+ ct="${t%${t#?}}"
t="${t#?}"
- e="${e#?}"
-
- [ "$ct" != "$ce" ] \
- && newcolor="" \
- || newcolor=""
+ ce="${e%${e#?}}"
+ e="${e#?}"
- [ ! "$ce" ] && newcolor="" \
+ case "$ce" in
+ "$ct")
+ newcolor=""
+ ;;
+ "")
+ newcolor=""
+ ;;
+ *)
+ newcolor=""
+ ;;
+ esac
[ "$lt" = " " ] && {
next_word=${t%% *}
@@ -73,10 +79,10 @@ typr_draw_text () {
}
- [ "$color" = "" ] &&{
+ [ "$color" = "" ] && {
[ "$ce" = " " ] && draw="${draw}_" || draw="${draw}$ce"
} || {
- draw="$draw$ct"
+ draw="$draw$ct"
}
i=$((i+1))
@@ -171,9 +177,17 @@ typr_main () {
correct_kp=0
export correct_kp total_kp
+ fstart=$(date +%s%N)
while true; do
typr_draw_text
+
+ # calculate performance
+ fend=$(date +%s%N)
+ msperframe=$(((fend-fstart)/1000000))
+ printf "%6s" "$msperframe"
+
c="$(tty_readc)"
+ fstart=$(date +%s%N)
case "$c" in
''|'') break;;
'')