blob: ab324edb95c9a2fada89521a062b3cd7d548b594 (
plain)
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
#!/bin/bash
# Copyright 1999-2017 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
EAPI=6
source tests-common.sh || exit
inherit eapi7-ver versionator
cutting() {
local x
for x in {1..1000}; do
ver_cut 1 1.2.3
ver_cut 1-2 1.2.3
ver_cut 2- 1.2.3
ver_cut 1- 1.2.3
ver_cut 3-4 1.2.3b_alpha4
ver_cut 5 1.2.3b_alpha4
ver_cut 1-2 .1.2.3
ver_cut 0-2 .1.2.3
ver_cut 2-3 1.2.3.
ver_cut 2- 1.2.3.
ver_cut 2-4 1.2.3.
done >/dev/null
}
cutting_versionator() {
local x
for x in {1..100}; do
get_version_component_range 1 1.2.3
get_version_component_range 1-2 1.2.3
get_version_component_range 2- 1.2.3
get_version_component_range 1- 1.2.3
get_version_component_range 3-4 1.2.3b_alpha4
get_version_component_range 5 1.2.3b_alpha4
get_version_component_range 1-2 .1.2.3
get_version_component_range 0-2 .1.2.3
get_version_component_range 2-3 1.2.3.
get_version_component_range 2- 1.2.3.
get_version_component_range 2-4 1.2.3.
done >/dev/null
}
replacing() {
local x
for x in {1..1000}; do
ver_rs 1 - 1.2.3
ver_rs 2 - 1.2.3
ver_rs 1-2 - 1.2.3.4
ver_rs 2- - 1.2.3.4
ver_rs 2 . 1.2-3
ver_rs 3 . 1.2.3a
ver_rs 2-3 - 1.2_alpha4
#ver_rs 3 - 2 "" 1.2.3b_alpha4
#ver_rs 3-5 _ 4-6 - a1b2c3d4e5
ver_rs 1 - .1.2.3
ver_rs 0 - .1.2.3
done >/dev/null
}
replacing_versionator() {
local x
for x in {1..100}; do
replace_version_separator 1 - 1.2.3
replace_version_separator 2 - 1.2.3
replace_version_separator 1-2 - 1.2.3.4
replace_version_separator 2- - 1.2.3.4
replace_version_separator 2 . 1.2-3
replace_version_separator 3 . 1.2.3a
replace_version_separator 2-3 - 1.2_alpha4
#replace_version_separator 3 - 2 "" 1.2.3b_alpha4
#replace_version_separator 3-5 _ 4-6 - a1b2c3d4e5
replace_version_separator 1 - .1.2.3
replace_version_separator 0 - .1.2.3
done >/dev/null
}
comparing() {
local x
for x in {1..1000}; do
ver_test 1b_p1 -le 1_p1
ver_test 1.1b -le 1.1
ver_test 12.2.5 -le 12.2b
ver_test 4.0 -le 5.0
ver_test 5 -le 5.0
ver_test 1.0_pre2 -le 1.0_p2
ver_test 1.0_alpha2 -le 1.0_p2
ver_test 1.0_alpha1 -le 1.0_beta1
ver_test 1.0_beta3 -le 1.0_rc3
ver_test 1.001000000000000001 -le 1.001000000000000002
done
}
comparing_versionator() {
local x
for x in {1..100}; do
version_is_at_least 1b_p1 1_p1
version_is_at_least 1.1b 1.1
version_is_at_least 12.2.5 12.2b
version_is_at_least 4.0 5.0
version_is_at_least 5 5.0
version_is_at_least 1.0_pre2 1.0_p2
version_is_at_least 1.0_alpha2 1.0_p2
version_is_at_least 1.0_alpha1 1.0_beta1
version_is_at_least 1.0_beta3 1.0_rc3
version_is_at_least 1.001000000000000001 1.001000000000000002
done
}
get_times() {
local factor=${1}; shift
echo "${*}"
local real=()
local user=()
for x in {1..5}; do
while read tt tv; do
case ${tt} in
real) real+=( $(dc -e "${tv} ${factor} * p") );;
user) user+=( $(dc -e "${tv} ${factor} * p") );;
esac
done < <( ( time -p "${@}" ) 2>&1 )
done
[[ ${#real[@]} == 5 ]] || die "Did not get 5 real times"
[[ ${#user[@]} == 5 ]] || die "Did not get 5 user times"
local sum
for v in real user; do
vr="${v}[*]"
sum=$(dc -e "${!vr} + + + + 3 k 5 / p")
vr="${v}[@]"
printf '%s %4.2f %4.2f %4.2f %4.2f %4.2f => %4.2f avg\n' \
"${v}" "${!vr}" "${sum}"
done
}
export LC_ALL=C
get_times 1 cutting
get_times 10 cutting_versionator
get_times 1 replacing
get_times 10 replacing_versionator
get_times 1 comparing
get_times 10 comparing_versionator
|