-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadvanced_benchmark.sh
More file actions
executable file
·91 lines (74 loc) · 3.84 KB
/
advanced_benchmark.sh
File metadata and controls
executable file
·91 lines (74 loc) · 3.84 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
#!/bin/bash
TARGET_SHELL="./build/venom"
BASH_SHELL="bash"
# ANSI Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m'
echo "══════════════════════════════════════════════════════"
echo " 🔥 ADVANCED VENOM SHELL vs BASH BENCHMARK 🔥 "
echo "══════════════════════════════════════════════════════"
measure() {
local shell=$1
local name=$2
local cmd=$3
if [ -x /usr/bin/time ]; then
/usr/bin/time -f "%es" $shell -c "$cmd" 2>&1
else
(time $shell -c "$cmd") 2>&1 | grep real | awk '{print $2}'
fi
}
run_test() {
local test_name="$1"
local venom_cmd="$2"
local bash_cmd="$3"
echo ""
echo "🧪 TEST: $test_name"
echo "------------------------------------------------------"
echo -n "🐢 Bash: "
measure "$BASH_SHELL" "Bash" "$bash_cmd"
echo -n "🚀 Venom: "
measure "$TARGET_SHELL" "Venom" "$venom_cmd"
}
# ☠️ TEST 1 — Arithmetic Hell
# arithmetic expansion, variable access, while loop
run_test "Arithmetic Hell (20M iterations)" \
'i=0; j=0; while [ $i -lt 20000000 ]; do j=$((j + i)); i=$((i + 1)); done; echo $j > /dev/null' \
'i=0; j=0; while [ $i -lt 20000000 ]; do j=$((j + i)); i=$((i + 1)); done; echo $j > /dev/null'
# ☠️ TEST 2 — Variable Scope Torture
# symbol table, variable lookup, function call overhead
# Reduced to 200 outer * 50000 inner = 10M ops to keep it reasonable but heavy
run_test "Variable Scope Torture (Func Calls)" \
'f() { a=0; while [ $a -lt 50000 ]; do a=$((a+1)); done; }; i=0; while [ $i -lt 200 ]; do f; i=$((i+1)); done' \
'f() { a=0; while [ $a -lt 50000 ]; do a=$((a+1)); done; }; i=0; while [ $i -lt 200 ]; do f; i=$((i+1)); done'
# ☠️ TEST 3 — Subshell Massacre
# fork / subshell, environment cloning
run_test "Subshell Massacre (1M iterations)" \
'i=0; while [ $i -lt 1000000 ]; do ( a=$i ); i=$((i+1)); done' \
'i=0; while [ $i -lt 1000000 ]; do ( a=$i ); i=$((i+1)); done'
# ☠️ TEST 4 — Expansion Storm
# parameter expansion, string handling, memory allocator
# NOTE: Adjusted for safety. 100k iterations of doubling/tripling is impossible.
# Changing to limited exponential growth (20 iterations) and then large linear append (50k).
run_test "Expansion Storm (Linear Append 500k)" \
's="x"; i=0; while [ $i -lt 500000 ]; do s="x$s"; i=$((i+1)); done; echo ${#s} > /dev/null' \
's="x"; i=0; while [ $i -lt 500000 ]; do s="x$s"; i=$((i+1)); done; echo ${#s} > /dev/null'
# ☠️ TEST 5 — Command Substitution Grinder
# command substitution, pipe + fork, capture output
run_test "Command Substitution Grinder (500k iterations)" \
'i=0; while [ $i -lt 100000 ]; do x=$(echo $i); i=$((i+1)); done' \
'i=0; while [ $i -lt 100000 ]; do x=$(echo $i); i=$((i+1)); done'
# ☠️ TEST 6 — Builtin vs External Stress
# builtin detection, exec path resolution
run_test "Builtin Stress (1M iterations)" \
'i=0; while [ $i -lt 1000000 ]; do true; :; i=$((i+1)); done' \
'i=0; while [ $i -lt 1000000 ]; do true; :; i=$((i+1)); done'
# ☠️ TEST 7 — Eval Explosion
# eval, parsing
run_test "Eval Explosion (100k iterations)" \
'i=0; while [ $i -lt 100000 ]; do eval "a$i=$i"; i=$((i+1)); done' \
'i=0; while [ $i -lt 100000 ]; do eval "a$i=$i"; i=$((i+1)); done'
echo ""
echo "══════════════════════════════════════════════════════"
echo " 🏁 BENCHMARK COMPLETE 🏁 "
echo "══════════════════════════════════════════════════════"