[DEPRECATED] Go implementation of plcbundle
1#!/bin/bash
2# did-resolve-benchmar.sh - Benchmark DID resolution performance
3
4set -e
5
6BUNDLE=${1:-1}
7SAMPLES=${2:-20}
8
9echo "═══════════════════════════════════════════════════════════"
10echo " DID Resolution Performance Benchmark"
11echo "═══════════════════════════════════════════════════════════"
12echo ""
13echo "Bundle: $BUNDLE"
14echo "Samples per position range: $SAMPLES"
15echo ""
16
17# Extract DIDs at different positions from a bundle
18echo "Extracting test DIDs from bundle $BUNDLE..."
19
20# Early positions (0-100)
21EARLY_DIDS=$(plcbundle export --bundles $BUNDLE | head -100 | jq -r '.did' | head -$SAMPLES)
22
23# Middle positions (~5000)
24MIDDLE_DIDS=$(plcbundle export --bundles $BUNDLE | head -5100 | tail -100 | jq -r '.did' | head -$SAMPLES)
25
26# Late positions (~9900)
27LATE_DIDS=$(plcbundle export --bundles $BUNDLE | tail -100 | jq -r '.did' | head -$SAMPLES)
28
29echo "✓ Extracted test DIDs"
30echo ""
31
32# Function to benchmark a set of DIDs
33benchmark_dids() {
34 local label="$1"
35 local dids="$2"
36
37 echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
38 echo "Testing: $label"
39 echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
40
41 local total_time=0
42 local count=0
43 local min_time=999999
44 local max_time=0
45
46 # Arrays to store individual timings
47 local -a timings
48
49 for did in $dids; do
50 # Run resolve and extract timing
51 output=$(plcbundle index resolve "$did" 2>&1)
52
53 # Extract "Total: XXms" from stderr
54 if [[ $output =~ Total:\ ([0-9.]+)([µm]?s) ]]; then
55 time_value="${BASH_REMATCH[1]}"
56 time_unit="${BASH_REMATCH[2]}"
57
58 # Convert to milliseconds
59 if [[ $time_unit == "µs" ]]; then
60 time_ms=$(echo "scale=3; $time_value / 1000" | bc)
61 elif [[ $time_unit == "ms" ]]; then
62 time_ms=$time_value
63 else
64 # Assume seconds
65 time_ms=$(echo "scale=3; $time_value * 1000" | bc)
66 fi
67
68 timings+=($time_ms)
69 total_time=$(echo "$total_time + $time_ms" | bc)
70 count=$((count + 1))
71
72 # Update min/max
73 if (( $(echo "$time_ms < $min_time" | bc -l) )); then
74 min_time=$time_ms
75 fi
76 if (( $(echo "$time_ms > $max_time" | bc -l) )); then
77 max_time=$time_ms
78 fi
79
80 printf "."
81 fi
82 done
83
84 echo ""
85
86 if [ $count -gt 0 ]; then
87 avg_time=$(echo "scale=2; $total_time / $count" | bc)
88
89 # Calculate median (sort and take middle)
90 IFS=$'\n' sorted=($(sort -n <<<"${timings[*]}"))
91 median_idx=$((count / 2))
92 median_time=${sorted[$median_idx]}
93
94 echo ""
95 echo "Results ($count samples):"
96 echo " Average: ${avg_time}ms"
97 echo " Median: ${median_time}ms"
98 echo " Min: ${min_time}ms"
99 echo " Max: ${max_time}ms"
100 else
101 echo " No successful timings"
102 fi
103
104 echo ""
105}
106
107# Run benchmarks
108benchmark_dids "Early Positions (0-100)" "$EARLY_DIDS"
109benchmark_dids "Middle Positions (~5000)" "$MIDDLE_DIDS"
110benchmark_dids "Late Positions (~9900)" "$LATE_DIDS"
111
112echo "═══════════════════════════════════════════════════════════"
113echo " Benchmark Complete"
114echo "═══════════════════════════════════════════════════════════"
115echo ""
116echo "Expected results with LoadOperation optimization:"
117echo " Early: ~2-5ms (only decompress first 1%)"
118echo " Middle: ~10-15ms (decompress ~50%)"
119echo " Late: ~20-30ms (decompress ~99%)"
120echo ""
121echo "If all positions show similar timing (~18ms), the optimization"
122echo "isn't working and LoadBundle is still being called."
123echo ""