-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark_libsay.sh
executable file
·117 lines (102 loc) · 2.49 KB
/
benchmark_libsay.sh
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
#
# benchmark_libsay.sh - Version: 1.1-202209.21.180000
# Simple libsay benchmark.
#
# Author: Megaf - https://github.com/Megaf/ - mmegaf [at] gmail [dot] com
# Date: 14/09/2022
# License: GPL 3
# URL/GitHub: https://github.com/Megaf/libsay/
#
# Usage:
# './benchmark_libsay.sh' to run it with the defaut 50 runs set.
# './benchmark_libsay.sh n' where n is the number of runs you want to try.
source libsay
[ ! "$*" ] && runs=50
[ "$*" ] && runs="$*"
clear
rst
say << EOM
TITLE: libsay Benchmark
INFO: Welcome to the
INFO: libsay Benchmark!
Just a simple benchmark
to test the lib's
performance on your system.
WARN: This benchmark depends
WARN: on 'libsay' and 'tput'.
EOM
say "INFO: The benchmark will
INFO: run the loop $runs times.
NOTICE: Please press any key
NOTICE: to start the benchmark
NOTICE: or 'Ctrl c' to quit."
read -r -n 1 -s
clear
tput sc
read -r -d '' bench_text << EOM
TITLE: libsay Benchmark
Welcome to the libsay Benchmark!
INFO: This benchmark will test the
INFO: performance of your system by
INFO: timing how long it takes to
INFO: print all the text/box in here.
NOTICE: This is a single core bench.
WARNING: This is not very serious.
DBG: Is there a Debug mode?
DEBUG: Debug message!
ERROR: Nothing went wrong! All good!
EOM
read -r -d '' text_bench << EOM
NOTICE: Benchmark is already running!
WARNING: Please don't touch anything!
INFO: This message will be printed
INFO: $runs times!
EOM
do_libsay_benchmark()
{
debug="true"
t="0"
while [ "$t" -lt "$runs" ]; do
tput rc
say "$bench_text"
say "$text_bench"
draw topleftcorner
draw top
draw top
draw top
draw toprightcorner
draw do_godown
draw leftside
draw do_space
draw do_space
draw do_space
draw rightside
draw do_godown
draw bottomleftcorner
draw bottom
draw bottom
draw bottom
draw bottomrightcorner
t="$((t+1))"
tp="$((t*100))"
p="$((tp/runs))"
bar="$((p/10))"
printf '\n\n%s' "Progress: |"
printf "%0.s=" "$(seq 1 "$bar")"
printf '%s' ">$p%"
done
}
start="$(date +%s.%3N)"
do_libsay_benchmark
end="$(date +%s.%3N)"
total_time="$(echo "scale=3; $end - $start" | bc)"
clear
read -r -d '' final_text << EOF
INFO: All done
NOTICE: Time taken:
$total_time seconds.
EOF
say "$final_text"
unset start end text_bench bench_text t runs debug total_time tp p bar libsay_url libsay_destination final_text
exit 0