-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathind_vs_assoc_array.sh
More file actions
executable file
·103 lines (81 loc) · 2.02 KB
/
ind_vs_assoc_array.sh
File metadata and controls
executable file
·103 lines (81 loc) · 2.02 KB
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
#! /bin/bash
#COLUMNS=320
#LINES=240
COLUMNS=$(tput cols)
LINES=$(tput lines)
ELEM_CNT=$((COLUMNS*LINES))
declare -A assoc
elems=$(seq 1 $ELEM_CNT)
clearStr=$(printf "_%.0s" $elems)
function assocTest {
#for ((i = 0; i < ELEM_CNT; ++i)); do
for i in $elems; do
assoc[$i]=" "
done
# tput cup 0 0
# printf %s "${assoc[@]}"
}
declare -a ind
function indTest {
#for ((i = 0; i < ELEM_CNT; ++i)); do
for i in $elems; do
ind[$i]=" "
done
# tput cup 0 0
# printf %s "${ind[@]}"
}
declare -a mixed
columns=$(seq 0 $((COLUMNS-1)))
anEmptyLine=$(printf "_%.0s" $columns)
for ((i = 0; i < LINES; ++i)); do
mixed[$i]="$anEmptyLine"
done
function mixTest {
for i in $elems; do
line=$((i / COLUMNS))
col=$((i % COLUMNS))
str=${mixed[line]}
mixed[$line]=${str:0:$col}"0"${str:$((col+1))}
done
}
function tputTest {
for i in $elems; do
line=$((i / COLUMNS + 1))
col=$((i % COLUMNS + 1))
#tput cup $line $col
#printf "\E[%i;%iH1" $line $col
echo -en "\E[${line};${col}H1"
#printf "1"
#str=${mixed[line]}
#mixed[$line]=${str:0:$col}"0"${str:$((col+1))}
done
}
# # # # var test # # # # #
function evalTest {
for i in $elems; do
#eval "myArr$i='$i'"
declare -g "myArr$i"=$(($i % 10))
done
}
function evalTest2 {
for i in $elems; do
eval "myArr$i='$((i % 10))'"
#declare -g "myArr$i"=$i
done
}
function printEval {
tput cup 0 0
rm -rf ./test.fifo
mkfifo ./test.fifo
tail -f ./test.fifo &
for i in $elems; do
eval "printf \"\$myArr$i\"" >> ./test.fifo
done
}
#echo "assoc:"; for t in {1..3}; do time { assocTest; echo; } ; read ; done
#echo "ind:"; for t in {1..3}; do time { indTest; echo; } ; read; done
#echo "mixed:"; for t in {1..3}; do time { mixTest; echo; } ; read; done
#echo "tput:"; for t in {1..3}; do time { tputTest; echo; } ; read; done
echo "eval:"; for t in {1..3}; do time { evalTest2; echo; } ; read; done
echo "peval:"; for t in {1..3}; do time { printEval; echo; }; read; done
#time { tput cup 0 0; printf "$clearStr"; }