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 pathquick-profile.sh
More file actions
82 lines (62 loc) · 2.01 KB
/
quick-profile.sh
File metadata and controls
82 lines (62 loc) · 2.01 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
#!/usr/bin/env bash
set -euo pipefail
# Quick profiling comparison between lint command and git commit hooks
echo "⚡ Quick Pre-commit Performance Comparison"
echo "========================================="
# Create a test shell script
TEST_FILE="quick-test.sh"
cat >"${TEST_FILE}" <<'EOF'
#!/usr/bin/env bash
echo "test"
if [ "$1" = "hello" ]; then
echo "world"
fi
EOF
echo "Testing with file: ${TEST_FILE}"
# Function to time a command
time_command() {
local cmd="$1"
local desc="$2"
echo ""
echo "🕐 ${desc}"
echo "Command: ${cmd}"
local start_time
start_time=$(python3 -c "import time; print(time.time())")
eval "${cmd}" >/dev/null 2>&1
local exit_code=$?
local end_time
end_time=$(python3 -c "import time; print(time.time())")
local duration
duration=$(python3 -c "print(f'{${end_time} - ${start_time}:.3f}')")
if [[ "${exit_code}" -eq 0 ]]; then
echo "✅ Success: ${duration}s"
else
echo "⚠️ Issues found: ${duration}s"
fi
return "${exit_code}"
}
# Test 1: Lint function
time_command "lint \"${TEST_FILE}\"" "Lint function (global config)"
# Test 2: Local pre-commit
time_command "pre-commit run --files \"${TEST_FILE}\"" "Local pre-commit (repo config)"
# Test 3: Simulate git commit process
echo ""
echo "🔄 Simulating git commit process..."
git add "${TEST_FILE}"
# Time the pre-commit hook execution in commit context
time_command "pre-commit run --hook-stage pre-commit" "Pre-commit in commit context"
# Reset
git reset HEAD "${TEST_FILE}" >/dev/null 2>&1
# Test 4: Individual timing of the shell script hook
echo ""
echo "🐚 Testing shell hook specifically..."
time_command "/Users/andrewrich/.config/git/hooks/lint-shell.sh \"${TEST_FILE}\"" "Shell hook directly"
# Cleanup
rm -f "${TEST_FILE}"
echo ""
echo "🎯 Analysis Tips:"
echo "- Compare 'lint function' vs 'local pre-commit' times"
echo "- Check if 'commit context' adds significant overhead"
echo "- Shell hook timing shows core processing time"
echo ""
echo "For detailed analysis, run: ./profile-hooks.sh"