@@ -7,8 +7,8 @@ echo "Chatbot Runtime Benchmark & Testing"
77echo " =========================================="
88echo " "
99
10- # Build both versions
11- echo " Building both versions..."
10+ # Build all versions
11+ echo " Building all versions..."
1212echo " "
1313
1414cd c
@@ -19,28 +19,46 @@ cd ..
1919cd zig
2020rm -rf zig-out .zig-cache > /dev/null 2>&1
2121mkdir -p zig-out/bin
22- zig build-exe src/main.zig -femit-bin=zig-out/bin/chat > /dev/null 2>&1
22+ zig build > /dev/null 2>&1
2323cd ..
2424
2525echo " Build complete!"
2626echo " "
2727
28- # Test C version
28+ # Test C17 version
2929echo " =========================================="
30- echo " C Version Testing & Benchmarking"
30+ echo " C17 Version Testing & Benchmarking"
3131echo " =========================================="
3232echo " "
3333echo " Running with test inputs..."
3434
35- C_START =$( date +%s%N)
36- c/./chat < test_inputs.txt > /tmp/c_output .txt 2>&1
37- C_END =$( date +%s%N)
38- C_TIME =$(( (C_END - C_START ) / 1000000 )) # milliseconds
35+ C17_START =$( date +%s%N)
36+ c/./chat-c17 < test_inputs.txt > /tmp/c17_output .txt 2>&1
37+ C17_END =$( date +%s%N)
38+ C17_TIME =$(( (C 17 _END - C 17 _START ) / 1000000 )) # milliseconds
3939
4040echo " Output:"
41- cat /tmp/c_output .txt
41+ cat /tmp/c17_output .txt
4242echo " "
43- echo " Execution time: ${C_TIME} ms"
43+ echo " Execution time: ${C17_TIME} ms"
44+ echo " "
45+
46+ # Test C23 version
47+ echo " =========================================="
48+ echo " C23 Version Testing & Benchmarking"
49+ echo " =========================================="
50+ echo " "
51+ echo " Running with test inputs..."
52+
53+ C23_START=$( date +%s%N)
54+ c/./chat-c23 < test_inputs.txt > /tmp/c23_output.txt 2>&1
55+ C23_END=$( date +%s%N)
56+ C23_TIME=$(( (C23 _END - C23 _START) / 1000000 )) # milliseconds
57+
58+ echo " Output:"
59+ cat /tmp/c23_output.txt
60+ echo " "
61+ echo " Execution time: ${C23_TIME} ms"
4462echo " "
4563
4664# Test Zig version
@@ -67,16 +85,19 @@ echo "Output Comparison"
6785echo " =========================================="
6886echo " "
6987
70- if diff -q /tmp/c_output.txt /tmp/zig_output.txt > /dev/null 2>&1 ; then
71- echo " ✓ Outputs are identical"
88+ OUTPUTS_MATCH=true
89+ if diff -q /tmp/c17_output.txt /tmp/c23_output.txt > /dev/null 2>&1 ; then
90+ echo " ✓ C17 and C23 outputs are identical"
7291else
73- echo " ✗ Outputs differ"
74- echo " "
75- echo " C output:"
76- cat /tmp/c_output.txt
77- echo " "
78- echo " Zig output:"
79- cat /tmp/zig_output.txt
92+ echo " ✗ C17 and C23 outputs differ"
93+ OUTPUTS_MATCH=false
94+ fi
95+
96+ if diff -q /tmp/c17_output.txt /tmp/zig_output.txt > /dev/null 2>&1 ; then
97+ echo " ✓ C17 and Zig outputs are identical"
98+ else
99+ echo " ✗ C17 and Zig outputs differ"
100+ OUTPUTS_MATCH=false
80101fi
81102
82103echo " "
@@ -87,16 +108,47 @@ echo "Runtime Comparison"
87108echo " =========================================="
88109echo " "
89110
90- if [ $C_TIME -lt $ZIG_TIME ]; then
91- RATIO=$( echo " scale=2; $ZIG_TIME / $C_TIME " | bc)
92- echo " C version is ${RATIO} x faster"
93- else
94- RATIO=$( echo " scale=2; $C_TIME / $ZIG_TIME " | bc)
95- echo " Zig version is ${RATIO} x faster"
111+ # Find the fastest
112+ MIN_TIME=$C17_TIME
113+ FASTEST=" C17"
114+ if [ $C23_TIME -lt $MIN_TIME ]; then
115+ MIN_TIME=$C23_TIME
116+ FASTEST=" C23"
117+ fi
118+ if [ $ZIG_TIME -lt $MIN_TIME ]; then
119+ MIN_TIME=$ZIG_TIME
120+ FASTEST=" Zig"
96121fi
97122
123+ echo " Fastest: $FASTEST (${MIN_TIME} ms)"
98124echo " "
99125echo " Summary:"
100- echo " C: ${C_TIME} ms"
126+ echo " C17: ${C17_TIME} ms"
127+ echo " C23: ${C23_TIME} ms"
101128echo " Zig: ${ZIG_TIME} ms"
102129echo " "
130+
131+ # Show ratios relative to fastest
132+ if [ $MIN_TIME -gt 0 ]; then
133+ C17_RATIO=$( echo " scale=2; $C17_TIME / $MIN_TIME " | bc)
134+ C23_RATIO=$( echo " scale=2; $C23_TIME / $MIN_TIME " | bc)
135+ ZIG_RATIO=$( echo " scale=2; $ZIG_TIME / $MIN_TIME " | bc)
136+ echo " Relative to fastest:"
137+ echo " C17: ${C17_RATIO} x"
138+ echo " C23: ${C23_RATIO} x"
139+ echo " Zig: ${ZIG_RATIO} x"
140+ echo " "
141+ fi
142+
143+ # Binary sizes
144+ echo " =========================================="
145+ echo " Binary Sizes"
146+ echo " =========================================="
147+ echo " "
148+ C17_SIZE=$( ls -lh c/chat-c17 | awk ' {print $5}' )
149+ C23_SIZE=$( ls -lh c/chat-c23 | awk ' {print $5}' )
150+ ZIG_SIZE=$( ls -lh zig/zig-out/bin/chat | awk ' {print $5}' )
151+ echo " C17: $C17_SIZE "
152+ echo " C23: $C23_SIZE "
153+ echo " Zig: $ZIG_SIZE "
154+ echo " "
0 commit comments