diff --git a/speedbench.sh b/speedbench.sh new file mode 100755 index 0000000..6467d3e --- /dev/null +++ b/speedbench.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +# OpenSSL Speed Benchmark Timer +# Measures execution time of openssl speed with multi-threading + +set -euo pipefail + +RED='\033[0;31m' +GREEN='\033[0;32m' +YELLOW='\033[1;33m' +BLUE='\033[0;34m' +NC='\033[0m' + +print_info() { + echo -e "${BLUE}[INFO]${NC} $1" +} + +print_success() { + echo -e "${GREEN}[SUCCESS]${NC} $1" +} + +print_warning() { + echo -e "${YELLOW}[WARNING]${NC} $1" +} + +print_error() { + echo -e "${RED}[ERROR]${NC} $1" +} + +if ! command -v openssl &> /dev/null; then + print_error "OpenSSL is not installed or not in PATH" + exit 1 +fi + +if ! command -v nproc &> /dev/null; then + print_error "nproc command is not available" + exit 1 +fi + +num_procs=$(nproc) +print_info "Number of processors detected: $num_procs" + +timestamp=$(date +"%Y%m%d_%H%M%S") +output_file="openssl_benchmark_${timestamp}.log" + +print_info "Starting OpenSSL speed benchmark..." +print_info "Command: openssl speed -multi $num_procs" +print_info "Output will be saved to: $output_file" + +start_time=$(date +%s.%N) + +if time openssl speed -multi "$num_procs" > "$output_file" 2>&1; then + end_time=$(date +%s.%N) + duration=$(echo "$end_time - $start_time" | bc -l) + print_success "Benchmark completed successfully!" + printf "${GREEN}Total execution time: %.2f seconds${NC}\n" "$duration" + print_info "Benchmark results saved to: $output_file" + echo "" + print_info "Quick summary from benchmark:" + echo "----------------------------------------" + tail -10 "$output_file" | grep -E "(^The|^rsa|^aes|^sha)" | head -5 || echo "No summary data found" + echo "----------------------------------------" +else + print_error "Benchmark failed to complete" + exit 1 +fi + +file_size=$(du -h "$output_file" | cut -f1) +print_info "Output file size: $file_size" +print_success "Script completed. Check $output_file for detailed results."