create project analytics

This commit is contained in:
wieerwill 2023-12-04 20:53:19 +01:00
parent 8137adf55f
commit 1e26ddb113
3 changed files with 121 additions and 1 deletions

26
Analytics.md Normal file
View File

@ -0,0 +1,26 @@
# Performance Analytics
## Day01
| Language | Status | Real Time | User Time | Sys Time |
| --- | --- | --- | --- | --- |
| Python | 0 | 0m0,071s | 0m0,060s | 0m0,008s |
| Rust | 0 | 0m0,078s | 0m0,052s | 0m0,026s |
| JavaScript | 0 | 0m0,089s | 0m0,085s | 0m0,012s |
| TypeScript | 0 | 0m1,001s | 0m2,188s | 0m0,158s |
## Day02
| Language | Status | Real Time | User Time | Sys Time |
| --- | --- | --- | --- | --- |
| Python | 0 | 0m0,032s | 0m0,016s | 0m0,016s |
| Rust | 0 | 0m0,063s | 0m0,044s | 0m0,020s |
| JavaScript | 0 | 0m0,044s | 0m0,032s | 0m0,012s |
| TypeScript | 0 | 0m1,013s | 0m2,059s | 0m0,160s |
## Day03
| Language | Status | Real Time | User Time | Sys Time |
| --- | --- | --- | --- | --- |
| Python | 0 | 0m0,054s | 0m0,043s | 0m0,011s |
| Rust | 0 | 0m0,059s | 0m0,032s | 0m0,024s |
| JavaScript | 0 | 0m0,067s | 0m0,036s | 0m0,032s |
| TypeScript | 0 | 0m1,014s | 0m2,128s | 0m0,155s |
## Day04
| Language | Status | Real Time | User Time | Sys Time |
| --- | --- | --- | --- | --- |
| Python | 0 | 0m16,137s | 0m16,020s | 0m0,117s |

View File

@ -1,5 +1,5 @@
[package]
name = "rust_solution_01"
name = "rust"
version = "0.1.0"
edition = "2021"

94
measure_performance.sh Executable file
View File

@ -0,0 +1,94 @@
#!/bin/bash
# Root directory where DayXX folders are located
ROOT_DIR="$(pwd)"
# Prepare Analytics.md file in the root directory
ANALYTICS_FILE="Analytics.md"
echo "# Performance Analytics" > $ANALYTICS_FILE
# Function to measure and append execution time to the analytics file
measure_execution_time() {
local day=$1
local language=$2
local script_dir=$3
local script_name=$4
local runner=$5
echo "Running $language script for $day: $runner $script_dir$script_name"
local real_time=""
local user_time=""
local sys_time=""
local EXEC_STATUS=""
cd "$script_dir"
if [ "$language" == "Rust" ]; then
if [ -d "$script_dir" ]; then
exec 3>&1 4>&2
TIME_RESULT=$( { time $runner 1>&3 2>&4; } 2>&1 )
EXEC_STATUS=$?
exec 3>&- 4>&-
real_time=$(echo "$TIME_RESULT" | grep real | awk '{print $2}')
user_time=$(echo "$TIME_RESULT" | grep user | awk '{print $2}')
sys_time=$(echo "$TIME_RESULT" | grep sys | awk '{print $2}')
echo "| $language | $EXEC_STATUS | $real_time | $user_time | $sys_time |" >> "$ROOT_DIR/$ANALYTICS_FILE"
else
echo "| $language | rust not executable | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE"
echo "Warning: $language script for $day not found or not executable"
fi
else
if [ -f "$script_name" ]; then
exec 3>&1 4>&2
TIME_RESULT=$( { time $runner $script_name 1>&3 2>&4; } 2>&1 )
EXEC_STATUS=$?
exec 3>&- 4>&-
real_time=$(echo "$TIME_RESULT" | grep real | awk '{print $2}')
user_time=$(echo "$TIME_RESULT" | grep user | awk '{print $2}')
sys_time=$(echo "$TIME_RESULT" | grep sys | awk '{print $2}')
echo "| $language | $EXEC_STATUS | $real_time | $user_time | $sys_time |" >> "$ROOT_DIR/$ANALYTICS_FILE"
else
echo "| $language | Not Found or Not Executable | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE"
echo "Warning: $language script for $day not found or not executable"
fi
fi
cd "$ROOT_DIR"
}
# Loop through each DayXX folder
for day_folder in $ROOT_DIR/Day*/; do
day=$(basename "$day_folder")
echo "\n## $day" >> $ANALYTICS_FILE
echo "| Language | Status | Real Time | User Time | Sys Time |" >> $ANALYTICS_FILE
echo "| --- | --- | --- | --- | --- |" >> $ANALYTICS_FILE
# Python
measure_execution_time "$day" "Python" "${day_folder}python/" "solution2.py" "python3"
# Rust
RUST_PROJECT_DIR="${day_folder}rust"
if [ ! -d "$RUST_PROJECT_DIR" ]; then
echo "Rust project directory not found for $day."
echo "| Rust | Directory Not Found | - | - | - |" >> "$ROOT_DIR/$ANALYTICS_FILE"
else
if [ ! -f "$RUST_PROJECT_DIR/target/release/rust" ]; then
echo "Compiled Rust binary not found. Building the Rust project in $RUST_PROJECT_DIR..."
(cd "$RUST_PROJECT_DIR" && cargo build --release)
fi
measure_execution_time "$day" "Rust" "$RUST_PROJECT_DIR" "" "cargo run --release"
fi
# JavaScript
measure_execution_time "$day" "JavaScript" "${day_folder}js/" "solution.js" "node"
# TypeScript
measure_execution_time "$day" "TypeScript" "${day_folder}ts/" "solution.ts" "ts-node"
echo "Processed $day"
done
echo "Performance measurement complete. Results are saved in $ANALYTICS_FILE."