Bash · 2837 bytes Raw Blame History
1 #!/bin/bash
2 # Performance test for memory pooling feature
3
4 echo "=== Memory Pool Performance Test ==="
5 echo ""
6
7 # Colors for output
8 RED='\033[0;31m'
9 GREEN='\033[0;32m'
10 YELLOW='\033[1;33m'
11 NC='\033[0m' # No Color
12
13 # Test command that exercises syntax highlighting
14 TEST_CMD='ls -la | grep ".f90" | head -5 ; echo "test $VAR" ; cd /tmp && pwd'
15
16 # Function to measure performance
17 measure_performance() {
18 local binary=$1
19 local label=$2
20
21 echo -e "${YELLOW}Testing: $label${NC}"
22
23 # Measure memory usage and timing
24 echo "1. Memory test (100 iterations of syntax highlighting):"
25
26 # Create a test script that exercises the highlighting
27 cat > /tmp/fortsh_test.sh << 'EOF'
28 for i in {1..100}; do
29 echo 'ls -la /usr/bin | grep "^-" | wc -l'
30 echo 'echo "Testing variable $HOME and path /etc/passwd"'
31 echo 'if [ -f /etc/passwd ]; then echo "found"; fi'
32 done
33 EOF
34
35 # Time the execution
36 TIME_OUTPUT=$(/usr/bin/time -v $binary < /tmp/fortsh_test.sh 2>&1 | grep -E "(User time|System time|Maximum resident|wall clock)")
37
38 echo "$TIME_OUTPUT"
39
40 # Interactive test with valgrind (if available)
41 if command -v valgrind > /dev/null 2>&1; then
42 echo ""
43 echo "2. Memory leak check (quick test):"
44 echo "$TEST_CMD" | valgrind --leak-check=summary --track-origins=yes $binary 2>&1 | grep -E "(definitely lost|indirectly lost|possibly lost|LEAK SUMMARY)" | head -10
45 fi
46
47 echo ""
48 }
49
50 # Build without memory pool
51 echo -e "${GREEN}Building WITHOUT memory pooling...${NC}"
52 make clean > /dev/null 2>&1
53 make MEMPOOL=0 > /dev/null 2>&1
54 if [ $? -ne 0 ]; then
55 echo -e "${RED}Build failed without memory pool${NC}"
56 exit 1
57 fi
58
59 cp bin/fortsh bin/fortsh_no_pool
60 measure_performance "bin/fortsh_no_pool" "WITHOUT Memory Pool"
61
62 # Build with memory pool
63 echo -e "${GREEN}Building WITH memory pooling...${NC}"
64 make clean > /dev/null 2>&1
65 make MEMPOOL=1 > /dev/null 2>&1
66 if [ $? -ne 0 ]; then
67 echo -e "${RED}Build failed with memory pool${NC}"
68 exit 1
69 fi
70
71 cp bin/fortsh bin/fortsh_with_pool
72 measure_performance "bin/fortsh_with_pool" "WITH Memory Pool"
73
74 # Quick interactive test
75 echo -e "${YELLOW}=== Quick Interactive Comparison ===${NC}"
76 echo "Testing command completion and highlighting..."
77
78 echo ""
79 echo "WITHOUT pool - Typing test:"
80 echo "$TEST_CMD" | bin/fortsh_no_pool 2>/dev/null | head -5
81
82 echo ""
83 echo "WITH pool - Typing test:"
84 echo "$TEST_CMD" | bin/fortsh_with_pool 2>/dev/null | head -5
85
86 # Run the memory pool test if it exists
87 if [ -f tests/test_memory_pool ]; then
88 echo ""
89 echo -e "${YELLOW}=== Memory Pool Unit Tests ===${NC}"
90 ./tests/test_memory_pool
91 fi
92
93 echo ""
94 echo -e "${GREEN}=== Performance Test Complete ===${NC}"
95 echo "Compare the 'Maximum resident set size' and timing values above."
96 echo "Lower memory usage and faster times indicate improvement."