System Performance Benchmark
Tests system performance and generates benchmark results. Measures CPU, disk, memory and network performance.
Published: May 07, 2024
Detailed Information
This script comprehensively tests system performance and generates benchmark results. Measures CPU, disk, memory and network performance.
What Does This Script Do?
This script measures system performance:
- Tests CPU performance
- Measures memory speed
- Tests disk read/write speed
- Measures network latency
- Creates detailed report
Why Should You Use It?
Performance benchmark is critical for system optimization:
- Performance Analysis: Understand system performance
- Optimization: Detect performance issues
- Comparison: Compare different systems
How to Use
Step-by-Step Usage Guide
1. Create Script File
nano benchmark.sh
2. Make Executable
chmod +x benchmark.sh
3. Run Script
./benchmark.sh
4. Review Report
cat benchmark_*.txt Requirements
Requirements
- bc: For mathematical calculations
- lscpu: For CPU information
Use Cases
Use Cases
1. System Performance Analysis
Test performance of a new server.
2. Before/After Optimization
Measure impact of optimization operations.
Examples
Usage Examples
Example 1: Basic Benchmark
./benchmark.sh Code
#!/bin/bash
# System Performance Benchmark
REPORT="benchmark_$(date +%Y%m%d_%H%M%S).txt"
echo "======================================"
echo " SYSTEM PERFORMANCE BENCHMARK"
echo "======================================"
echo "Started: $(date)"
echo ""
{
echo "======================================"
echo " CPU BENCHMARK"
echo "======================================"
echo "CPU Information:"
lscpu | grep -E "Model name|CPU\(s\)|Thread|Core"
echo ""
echo "CPU Speed Test (calculating pi):"
time echo "scale=5000; 4*a(1)" | bc -l > /dev/null
echo ""
echo "======================================"
echo " MEMORY BENCHMARK"
echo "======================================"
echo "Memory Information:"
free -h
echo ""
echo "Memory Speed Test:"
MEM_SIZE=100M
time dd if=/dev/zero of=/tmp/memtest bs=$MEM_SIZE count=1 oflag=direct 2>&1 | tail -1
echo ""
echo "======================================"
echo " DISK BENCHMARK"
echo "======================================"
echo "Disk Write Test:"
time dd if=/dev/zero of=/tmp/disktest bs=1G count=1 oflag=direct 2>&1 | tail -1
echo ""
echo "Disk Read Test:"
time dd if=/tmp/disktest of=/dev/null bs=1G 2>&1 | tail -1
echo ""
rm -f /tmp/disktest
echo "======================================"
echo " NETWORK BENCHMARK"
echo "======================================"
echo "Network Speed Test (ping):"
ping -c 10 8.8.8.8 | tail -2
echo ""
echo "======================================"
echo "Benchmark completed: $(date)"
echo "======================================"
} | tee "$REPORT"
echo ""
echo "✓ Benchmark report saved to: $REPORT"
Usage
chmod +x benchmark.sh
./benchmark.sh
Troubleshooting
Troubleshooting
Problem: "bc: command not found"
Solution: Install bc:
sudo apt-get install bc