Skip to content

Instantly share code, notes, and snippets.

@krautcat
Last active August 29, 2017 17:16
Show Gist options
  • Select an option

  • Save krautcat/603d37a36d742febce9c3420c576425d to your computer and use it in GitHub Desktop.

Select an option

Save krautcat/603d37a36d742febce9c3420c576425d to your computer and use it in GitHub Desktop.
Check reactivity of different interpeters, i.e. speed of startup
#!/usr/bin/env bash
LANG=en_US.UTF-8
__CMD=( "python"
"ruby"
"perl"
"lua5.3"
"tclsh"
"bash"
)
__V=( "-V" # Python
"-v" # Ruby
"-v | awk 'FNR==2 {print}'" # Perl
"-v" # Lua
"printf 'puts [info patchlevel];exit 0' | " # Tcl
"--version | awk 'FNR==1 {print}'" # Bash
)
_pretty_banner() {
local _str="${1// /\$}"
local _sym=$2
local _num=$3
local _v
local _italic
local _bold
local _normal
_italic=$(tput sitm)
_bold=$(tput bold)
_normal=$(tput sgr0)
_v=$(printf "%-${_num}s${_italic}${_bold}%s${_normal}%-${_num}s" "$_sym" "$_str" "$_sym")
_v="${_v// /$_sym}"
printf "%s\n" "${_v//\$/ }"
}
_pretty_out() {
local _filler="~"
local _banner_len=22
local _test_str=" test"
(( _len_str = ${#1} + ${#_test_str} ))
if (( _len_str % 2 == 0 )); then
_pretty_banner "${1}${_test_str}" $_filler $(( _banner_len / 2 - _len_str / 2 ))
else
_pretty_banner "${1} ${_test_str}" $_filler $(( _banner_len / 2 - (_len_str / 2 + 1) ))
fi
}
_get_max_len() {
local _max=0
for __str in $1; do
if (( ${#__str} > _max )); then
_max=${#__str}
fi
done
}
_get_lang_name() {
if [[ $1 == "lua5.3" ]]; then
printf "lua"
else
printf "%s" "$1"
fi
}
_print_version() {
local _version_str=""
local _max_len
local _lang
_lang=$(_get_lang_name "$1")
_max_len=$(_get_max_len @__CMD)
if [[ $_lang =~ (perl|bash) ]]; then
_version_str=$(eval "$1 $2")
elif [[ $_lang == "tclsh" ]]; then
_version_str=$(eval "$2 $1")
else
_version_str=$($1 "$2")
fi
printf "\e[1m%${_max_len}s\e[0m version: %s\n" "$_lang" "$_version_str"
}
_main() {
tabs -4
_pretty_banner "" "\"" 22
printf "%s How do I test %s\n" "-----" "-----"
printf "\n\ttime for _ in {1..1000}; do\n\t\t<interpreter__CMD> - <<< exit\n\tdone\n\n"
_pretty_banner "" "\"" 22
for ((i=0; i<${#__CMD[@]}; ++i)); do
_pretty_out "$(_get_lang_name "${__CMD[i]}")"
_print_version "${__CMD[i]}" "${__V[i]}"
# shellcheck disable=2167
for _ in {1..2}; do
printf "\e[4mTest #%s\e[0m:\t" "$_"
if [[ ${__CMD[i]} == "lua5.3" ]]; then
(
# shellcheck disable=2165
time for _ in {1..1000}; do
${__CMD[i]} 2> /dev/null - <<< exit
done
) 2>&1 | awk 'FNR==2 {print}'
else
(
# shellcheck disable=2165
time for _ in {1..1000}; do
${__CMD[i]} - <<< exit
done
) 2>&1 | awk 'FNR==2 {print}'
fi
done
printf "\n"
done
tabs -8
}
_main "$@"
@krautcat
Copy link
Author

krautcat commented Aug 29, 2017

Result on my working desktop

  • Intel Core i7-6700 @ 3.4GHz
  • Kingston 2x16Gb DDR4 @ 2133MHz
  • Samsung SSD 850 EVO 250GB
  • Ubuntu 16.04
~~~~~python  test~~~~~
python version: Python 3.5.2
Test #1:    real    0m41.708s
Test #2:    real    0m42.520s

~~~~~~ruby  test~~~~~~
ruby version: ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
Test #1:    real    0m22.258s
Test #2:    real    0m22.110s

~~~~~~perl  test~~~~~~
perl version: This is perl 5, version 22, subversion 1 (v5.22.1) built for x86_64-linux-gnu-thread-multi
Test #1:    real    0m1.098s
Test #2:    real    0m1.776s

~~~~~~~lua test~~~~~~~
lua version: Lua 5.3.1  Copyright (C) 1994-2015 Lua.org, PUC-Rio
Test #1:    real    0m1.322s
Test #2:    real    0m1.736s

~~~~~~tclsh test~~~~~~
tclsh version: 8.6.5
Test #1:    real    0m3.005s
Test #2:    real    0m3.025s

~~~~~~bash  test~~~~~~
bash version: GNU bash, version 4.3.48(1)-release (x86_64-pc-linux-gnu)
Test #1:    real    0m0.826s
Test #2:    real    0m1.857s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment