@@ -3,37 +3,46 @@ name: Heap Permutation Benchmark
33on :
44 push :
55 branches : [ "main" ]
6- pull_request :
7- branches : [ "main" ]
86 workflow_dispatch :
97
108jobs :
11- run-heap-perm :
12- name : Build and Benchmark Heap's Algorithm
9+ benchmark :
10+ name : Build and Profile
1311 runs-on : ubuntu-latest
1412
1513 steps :
1614 - name : Checkout Repository
1715 uses : actions/checkout@v4
1816
19- - name : Hardware Diagnostics (CPU Info)
20- # Using '|| true' to prevent exit code 1 if a string is not found
17+ - name : Get Hardware Info
18+ id : cpu_info
2119 run : |
22- echo "========== Hardware Environment =========="
23- lscpu | grep "Model name" || true
24- lscpu | grep "CPU MHz" || true
25- echo "------------------------------------------"
26- echo "Full LSCPU Output for Reference:"
27- lscpu
28- echo "=========================================="
20+ CPU_MODEL=$(lscpu | grep "Model name" | cut -d':' -f2 | sed 's/^[ \t]*//')
21+ echo "CPU_MODEL=$CPU_MODEL" >> $GITHUB_ENV
2922
3023 - name : Compile heap_perm.cpp
31- run : g++ -O3 heap_perm.cpp -o heap_perm_test
24+ run : g++ -O3 -std=c++11 heap_perm.cpp -o heap_perm_test -pthread
25+
26+ - name : Run and Capture Performance
27+ run : |
28+ # Use /usr/bin/time -f to get exactly what we want: the elapsed seconds
29+ # Redirecting algorithm output to /dev/null
30+ /usr/bin/time -f "%e" ./heap_perm_test > /dev/null 2> time_output.txt
31+
32+ EXEC_TIME=$(cat time_output.txt)
33+
34+ # Create a beautiful Markdown Summary
35+ echo "### 🚀 Algorithmic Performance Report" >> $GITHUB_STEP_SUMMARY
36+ echo "| Detail | Information |" >> $GITHUB_STEP_SUMMARY
37+ echo "| :--- | :--- |" >> $GITHUB_STEP_SUMMARY
38+ echo "| **Algorithm** | Heap's Permutation (Iterative) |" >> $GITHUB_STEP_SUMMARY
39+ echo "| **Target Size (N)** | 12 |" >> $GITHUB_STEP_SUMMARY
40+ echo "| **Execution Time** | \`${EXEC_TIME}s\` |" >> $GITHUB_STEP_SUMMARY
41+ echo "| **CPU Architecture** | ${{ env.CPU_MODEL }} |" >> $GITHUB_STEP_SUMMARY
42+ echo "| **Optimization** | G++ -O3 (Standard CI) |" >> $GITHUB_STEP_SUMMARY
43+ echo "" >> $GITHUB_STEP_SUMMARY
44+ echo "✅ *Benchmark completed in cloud environment.*" >> $GITHUB_STEP_SUMMARY
3245
33- - name : Execution and Performance Profiling
34- # If your code requires manual input, it might hang.
35- # I added 'echo 10 |' as a placeholder to prevent hanging if cin is used.
46+ - name : Display Result in Console
3647 run : |
37- echo "Starting performance profiling..."
38- echo 10 | time ./heap_perm_test > /dev/null
39- echo "Profiling completed."
48+ echo "Benchmark finished. Check the 'Summary' tab for the full report."
0 commit comments