#!/bin/bash # math-optimize.sh - Optimize mathematical functions for Qwen Code echo "Optimizing mathematical functions for Qwen Code..." # Create results directory if it doesn't exist mkdir -p .qwen/results # Run benchmarks to establish baseline echo "Establishing performance baseline..." go test -bench=. -benchmem ./pkg/uniswap/... ./pkg/math/... > .qwen/results/baseline-benchmarks.log # Run CPU profiling echo "Running CPU profiling..." go test -bench=. -cpuprofile=.qwen/results/baseline-cpu.prof ./pkg/uniswap/... ./pkg/math/... > .qwen/results/baseline-cpu.log # Run memory profiling echo "Running memory profiling..." go test -bench=. -memprofile=.qwen/results/baseline-mem.prof ./pkg/uniswap/... ./pkg/math/... > .qwen/results/baseline-mem.log # Analyze profiling results echo "Analyzing profiling results..." go tool pprof -top .qwen/results/baseline-cpu.prof > .qwen/results/cpu-top.log go tool pprof -top .qwen/results/baseline-mem.prof > .qwen/results/mem-top.log # Generate flame graphs (if go-torch is available) if command -v go-torch &> /dev/null; then echo "Generating flame graphs..." go-torch .qwen/results/baseline-cpu.prof > .qwen/results/cpu-flame.svg go-torch --alloc_objects .qwen/results/baseline-mem.prof > .qwen/results/mem-flame.svg fi echo "Mathematical optimization analysis complete!" echo "Baseline results saved to .qwen/results/" echo "Review .qwen/results/cpu-top.log and .qwen/results/mem-top.log for optimization opportunities"