Last active
December 30, 2024 08:51
-
-
Save jaggzh/4f4159b1b137cbc9553efb7d8364f0c9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Source at: https://gist.github.com/jaggzh/4f4159b1b137cbc9553efb7d8364f0c9 | |
. ansi.sh # ansi.sh from: https://gist.github.com/jaggzh/6b3746475bbde5a077dfaeae793b7d1f | |
bgblu=$'\e[44m' | |
bmag=$'\e[35m' | |
whi=$'\e[37m' | |
rst=$'\e[0m' | |
# blank to disable | |
bash=1 | |
perl=1 | |
python=1 | |
php= | |
echo; echo; | |
#################################### | |
# 1000 full execution overhead tests | |
if [[ -n $bash ]]; then | |
echo | |
echo -n "${bgblu}${whi}bash -c loop, of 1000 separate executions, of ${bmag}bash$whi Hello World$rst: " | |
/usr/bin/time -f '%e' bash -c 'for i in {1..1000}; do bash -c "echo Hello world"; done > /dev/null' | |
echo | |
echo -n "${bgblu}${whi}bash -c loop, of 1000 executions, of ${bmag}perl$whi Hello World $rst: " | |
/usr/bin/time -f '%e' bash -c 'for ((i=0;i<1000;i++)); do perl -E "say \"Hello world\";"; done > /dev/null' | |
fi | |
if [[ -n $python ]]; then | |
echo | |
echo -n "${bgblu}${whi}bash -c loop, of 1000 executions, of ${bmag}python$whi Hello World $rst: " | |
/usr/bin/time -f '%e' bash -c 'for ((i=0;i<1000;i++)); do python -c "print(\"Hello world\");"; done > /dev/null' | |
fi | |
if [[ -n $php ]]; then | |
echo | |
echo -n "${bgblu}${whi}bash -c loop, of 1000 executions, of ${bmag}php$whi Hello World $rst: " | |
/usr/bin/time -f '%e' bash -c 'for ((i=0;i<1000;i++)); do php -r "echo \"Hello world\n\";"; done > /dev/null' | |
fi | |
#################################### | |
# 10 000 000 in-language tests | |
if [[ -n $bash ]]; then | |
echo | |
echo -n "${bgblu}${whi}bash -c execution of a ${bmag}bash {1..1000000}; loop$whi of 1000000 echo Hello World $rst: " | |
/usr/bin/time -f '%e' bash -c 'for i in {1..1000000}; do echo "Hello world"; done > /dev/null' | |
echo -n "${bgblu}${whi}bash -c execution of a ${bmag}bash ((;;)); loop$whi of 1000000 echo Hello World $rst: " | |
/usr/bin/time -f '%e' bash -c 'for ((i=0; i<1000000; i++)); do echo "Hello world"; done > /dev/null' | |
fi | |
if [[ -n $perl ]]; then | |
echo -n "${bgblu}${whi}bash -c execution of ${bmag}perl loop$whi of 1000000 Hello Worlds $rst: " | |
/usr/bin/time -f '%e' bash -c 'perl -E "for (my \$i=0; \$i<1000000; \$i++) { say \"Hello world\"; }" >/dev/null' | |
fi | |
if [[ -n $python ]]; then | |
echo | |
echo -n "${bgblu}${whi}bash -c execution of ${bmag}python loop$whi of 1000000 Hello Worlds $rst: " | |
/usr/bin/time -f '%e' bash -c 'python -c "for i in range(1000000): print(\"Hello world\");" >/dev/null' | |
fi | |
if [[ -n $php ]]; then | |
echo | |
echo -n "${bgblu}${whi}bash -c execution of ${bmag}php loop$whi of 1000000 Hello Worlds $rst: " | |
/usr/bin/time -f '%e' bash -c 'php -r "\$i=0; while(\$i < 1000000) { echo \"Hello world\n\"; \$i++; }" >/dev/null' | |
fi | |
echo; echo; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment