|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +echo "=== NetQuack Performance Comparison ===" |
| 4 | +echo "" |
| 5 | + |
| 6 | +# Change to the project root directory (parent of script location) |
| 7 | +CWD="$(cd "$(dirname "$0")/.." && pwd)" |
| 8 | +cd "$CWD" |
| 9 | + |
| 10 | +# Create results directory in build (gitignored) |
| 11 | +mkdir -p build/benchmark_results |
| 12 | + |
| 13 | +# Function to create benchmark SQL with specified load command |
| 14 | +create_benchmark_sql() { |
| 15 | + local load_command="$1" |
| 16 | + local version_label="$2" |
| 17 | + local output_file="$3" |
| 18 | + |
| 19 | + cat > "$output_file" << EOF |
| 20 | +${load_command} |
| 21 | +
|
| 22 | +-- Create test data |
| 23 | +CREATE TABLE benchmark_urls AS SELECT * FROM (VALUES |
| 24 | + ('https://www.example.com/path?query=value#fragment'), |
| 25 | + ('http://subdomain.example.co.uk:8080/long/path/to/file.html?param1=value1¶m2=value2'), |
| 26 | + ('ftp://user:[email protected]:21/directory/file.zip'), |
| 27 | + ('https://blog.example.org/2023/12/article-title.html'), |
| 28 | + ('http://api.service.example.net:3000/v1/users/123?format=json'), |
| 29 | + ('https://cdn.assets.example.com/images/logo.png'), |
| 30 | + |
| 31 | + ('http://localhost:8080/debug'), |
| 32 | + ('https://secure.payment.example.gov:8443/transaction?id=abc123'), |
| 33 | + ('https://example.com') |
| 34 | +) AS t(url); |
| 35 | +
|
| 36 | +-- Expand dataset |
| 37 | +CREATE TABLE large_benchmark_urls AS |
| 38 | +WITH RECURSIVE series(i) AS ( |
| 39 | + SELECT 1 |
| 40 | + UNION ALL |
| 41 | + SELECT i + 1 FROM series WHERE i <= 3000 |
| 42 | +) |
| 43 | +SELECT url FROM benchmark_urls CROSS JOIN series; |
| 44 | +
|
| 45 | +.timer on |
| 46 | +.print '=== ${version_label} BENCHMARKS ===' |
| 47 | +
|
| 48 | +.print 'extract_schema:' |
| 49 | +SELECT extract_schema(url) FROM large_benchmark_urls; |
| 50 | +
|
| 51 | +.print 'extract_host:' |
| 52 | +SELECT extract_host(url) FROM large_benchmark_urls; |
| 53 | +
|
| 54 | +.print 'extract_port:' |
| 55 | +SELECT extract_port(url) FROM large_benchmark_urls; |
| 56 | +
|
| 57 | +.print 'extract_path:' |
| 58 | +SELECT extract_path(url) FROM large_benchmark_urls; |
| 59 | +
|
| 60 | +.print 'extract_query_string:' |
| 61 | +SELECT extract_query_string(url) FROM large_benchmark_urls; |
| 62 | +
|
| 63 | +.print 'extract_domain:' |
| 64 | +SELECT extract_domain(url) FROM large_benchmark_urls; |
| 65 | +
|
| 66 | +.print 'extract_subdomain:' |
| 67 | +SELECT extract_subdomain(url) FROM large_benchmark_urls; |
| 68 | +
|
| 69 | +.print 'extract_tld:' |
| 70 | +SELECT extract_tld(url) FROM large_benchmark_urls; |
| 71 | +
|
| 72 | +.print 'extract_extension:' |
| 73 | +SELECT extract_extension(url) FROM large_benchmark_urls; |
| 74 | +EOF |
| 75 | +} |
| 76 | + |
| 77 | +# Create temporary directory |
| 78 | +mkdir -p build/tmp |
| 79 | + |
| 80 | +# Create benchmark SQL files using the DRY function |
| 81 | +create_benchmark_sql "FORCE INSTALL netquack FROM community; LOAD netquack;" "PUBLISHED VERSION" "build/tmp/published_benchmark.sql" |
| 82 | +create_benchmark_sql "LOAD './build/release/extension/netquack/netquack.duckdb_extension';" "local VERSION" "build/tmp/local_benchmark.sql" |
| 83 | + |
| 84 | +echo "Step 1: Installing and benchmarking PUBLISHED NetQuack extension..." |
| 85 | +duckdb < build/tmp/published_benchmark.sql > build/benchmark_results/published_full_output.txt 2>&1 |
| 86 | + |
| 87 | +echo "Step 2: Running benchmarks on LOCAL implementation..." |
| 88 | +./build/release/duckdb < build/tmp/local_benchmark.sql > build/benchmark_results/local_full_output.txt 2>&1 |
| 89 | + |
| 90 | +echo "Step 3: Generating comparison analysis..." |
| 91 | + |
| 92 | +# Extract times and calculate improvements |
| 93 | +echo "📊 RESULTS SUMMARY:" > build/benchmark_results/analysis.txt |
| 94 | +echo "" >> build/benchmark_results/analysis.txt |
| 95 | + |
| 96 | +echo "| Function | Published Time | Local Time | Improvement |" >> build/benchmark_results/analysis.txt |
| 97 | +echo "|----------|----------------|----------------|-------------|" >> build/benchmark_results/analysis.txt |
| 98 | + |
| 99 | +# Extract timing data using a more robust approach |
| 100 | +functions=("extract_schema" "extract_host" "extract_port" "extract_path" "extract_query_string" "extract_domain" "extract_subdomain" "extract_tld" "extract_extension") |
| 101 | + |
| 102 | +# Extract all times into temporary files |
| 103 | +grep "Run Time" build/benchmark_results/published_full_output.txt | grep -o "real [0-9.]*" | cut -d' ' -f2 > build/tmp/published_times.txt |
| 104 | +grep "Run Time" build/benchmark_results/local_full_output.txt | grep -o "real [0-9.]*" | cut -d' ' -f2 > build/tmp/local_times.txt |
| 105 | + |
| 106 | +# Process each function |
| 107 | +for i in {0..9}; do |
| 108 | + func=${functions[$i]} |
| 109 | + line_num=$((i + 1)) |
| 110 | + |
| 111 | + published_time=$(sed -n "${line_num}p" build/tmp/published_times.txt) |
| 112 | + local_time=$(sed -n "${line_num}p" build/tmp/local_times.txt) |
| 113 | + |
| 114 | + if [ ! -z "$published_time" ] && [ ! -z "$local_time" ]; then |
| 115 | + improvement=$(echo "scale=1; $published_time / $local_time" | bc -l) |
| 116 | + echo "| ${func} | ${published_time}s | ${local_time}s | ${improvement}x faster |" >> build/benchmark_results/analysis.txt |
| 117 | + fi |
| 118 | +done |
| 119 | + |
| 120 | +# Clean up timing files |
| 121 | +rm -f build/tmp/published_times.txt build/tmp/local_times.txt |
| 122 | + |
| 123 | +echo "" |
| 124 | +echo "✅ Benchmark comparison complete!" |
| 125 | +echo "" |
| 126 | +cat build/benchmark_results/analysis.txt |
0 commit comments