commit:     a3c6899e26bb97644ba7aa919db794854172be5a
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Wed Sep  6 14:59:17 2017 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Wed Sep  6 14:59:17 2017 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a3c6899e

eapi7-ver.eclass: Add some trivial benchmark

 eclass/tests/eapi7-ver:benchmark.sh | 73 +++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)

diff --git a/eclass/tests/eapi7-ver:benchmark.sh 
b/eclass/tests/eapi7-ver:benchmark.sh
new file mode 100755
index 00000000000..6a1001473b4
--- /dev/null
+++ b/eclass/tests/eapi7-ver:benchmark.sh
@@ -0,0 +1,73 @@
+#!/bin/bash
+# Copyright 1999-2017 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=6
+
+source tests-common.sh
+
+inherit eapi7-ver
+
+cutting() {
+       local x
+       for x in {1..1000}; do
+               version_cut 1-2 1.2.3
+               version_cut 2- 1.2.3
+               version_cut 1- 1.2.3
+               version_cut 3-4 1.2.3b_alpha4
+               version_cut 5 1.2.3b_alpha4
+               version_cut 1-2 .1.2.3
+               version_cut 0-2 .1.2.3
+               version_cut 2-3 1.2.3.
+               version_cut 2- 1.2.3.
+               version_cut 2-4 1.2.3.
+       done >/dev/null
+}
+
+replacing() {
+       local x
+       for x in {1..1000}; do
+               version_rs 2 - 1.2.3
+               version_rs 2 . 1.2-3
+               version_rs 3 . 1.2.3a
+               version_rs 2-3 - 1.2_alpha4
+               version_rs 3 - 2 "" 1.2.3b_alpha4
+               version_rs 3-5 _ 4-6 - a1b2c3d4e5
+               version_rs 1 - .1.2.3
+               version_rs 0 - .1.2.3
+               version_rs 3 . 1.2.3
+       done >/dev/null
+}
+
+get_times() {
+       echo "${*}"
+       local real=()
+       local user=()
+
+       for x in {1..5}; do
+               while read tt tv; do
+                       case ${tt} in
+                               real) real+=( ${tv} );;
+                               user) user+=( ${tv} );;
+                       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\n' \
+                       "${v}" "${!vr}" "${sum}"
+       done
+}
+
+export LC_ALL=C
+
+get_times cutting
+get_times replacing

Reply via email to