This repository was archived by the owner on Apr 19, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdetailed-profile.sh
More file actions
executable file
·113 lines (94 loc) · 2.78 KB
/
detailed-profile.sh
File metadata and controls
executable file
·113 lines (94 loc) · 2.78 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/usr/bin/env bash
set -euo pipefail
echo "🔍 Detailed Pre-commit Performance Analysis"
echo "==========================================="
# Create test file
TEST_FILE="detail-test.sh"
cat >"${TEST_FILE}" <<'EOF'
#!/usr/bin/env bash
echo "test script"
if [ "$1" = "debug" ]; then
echo "debug mode"
fi
EOF
# Function to time with Python (more reliable than bc)
time_cmd() {
local description="$1"
shift
local cmd="$*"
echo ""
echo "📊 ${description}"
echo "Command: ${cmd}"
echo "----------------------------------------"
# Time multiple runs
local times=()
for i in {1..3}; do
local result
result=$(python3 -c "
import subprocess
import time
import sys
start = time.time()
try:
result = subprocess.run('${cmd}', shell=True, capture_output=True, text=True)
end = time.time()
duration = end - start
print(f'{duration:.3f}')
sys.exit(result.returncode)
except Exception as e:
end = time.time()
duration = end - start
print(f'{duration:.3f}')
sys.exit(1)
" 2>/dev/null)
local exit_code=$?
times+=("${result}")
echo " Run ${i}: ${result}s (exit: ${exit_code})"
done
# Calculate average
local avg
avg=$(python3 -c "
times = [${times[0]}, ${times[1]}, ${times[2]}]
avg = sum(times) / len(times)
print(f'{avg:.3f}')
")
echo " Average: ${avg}s"
echo "========================================="
}
# Profile each component
echo ""
echo "🧪 Component Analysis"
# 1. Global lint function
time_cmd "Global lint function" "lint \"${TEST_FILE}\""
# 2. Local pre-commit
time_cmd "Local pre-commit run" "pre-commit run --files \"${TEST_FILE}\""
# 3. Direct shell hook
time_cmd "Shell hook directly" "/Users/andrewrich/.config/git/hooks/lint-shell.sh \"${TEST_FILE}\""
# 4. Individual tools
echo ""
echo "🔧 Individual Tool Performance"
time_cmd "ShellCheck only" "shellcheck \"${TEST_FILE}\""
time_cmd "shfmt only" "shfmt -d -i 2 -ci -bn \"${TEST_FILE}\""
# 5. Environment costs
echo ""
echo "🏗️ Environment Overhead Analysis"
time_cmd "Pre-commit environment check" "pre-commit --version"
# 6. Config loading
time_cmd "Global config access" "pre-commit run --help --config ~/.config/pre-commit/config.yaml"
time_cmd "Local config access" "pre-commit run --help"
# Test with actual commit simulation
echo ""
echo "🔄 Commit Simulation"
git add "${TEST_FILE}"
time_cmd "Commit hook simulation" "pre-commit run --hook-stage pre-commit"
git reset HEAD "${TEST_FILE}" >/dev/null 2>&1
# Cleanup
rm -f "${TEST_FILE}"
echo ""
echo "🎯 Performance Insights"
echo "======================="
echo "The detailed timing above should reveal:"
echo "1. Global vs local config loading differences"
echo "2. Environment setup overhead"
echo "3. Individual tool execution times"
echo "4. Commit context vs direct execution differences"