This repo contains benchmarks (run with Go v1.23.0) that compare the performance of two CORS middleware libraries:
- the more popular rs/cors (v1.11.1), and
- the more user-friendly jub0bs/cors (v0.5.2).
Run the following commands in your shell (preferably on an idle machine):
git clone https://github.com/jub0bs/cors-benchmarks
cd cors-benchmarks
go test -run ^$ -bench . -count 10 > benchmark_results.txt
benchstat -col "/mw@(rs-cors jub0bs-cors)" -row "/req" benchmark_results.txt
goos: darwin
goarch: amd64
pkg: github.com/jub0bs/cors-benchmarks
cpu: Intel(R) Core(TM) i7-6700HQ CPU @ 2.60GHz
│ rs-cors │ jub0bs-cors │
│ sec/op │ sec/op vs base │
single_vs_actual 643.7n ± 2% 688.6n ± 1% +6.98% (p=0.000 n=10)
multiple_vs_actual 661.2n ± 1% 690.2n ± 1% +4.39% (p=0.000 n=10)
pathological_vs_actual 721.0n ± 1% 773.5n ± 1% +7.28% (p=0.000 n=10)
many_vs_actual 680.4n ± 1% 663.0n ± 0% -2.56% (p=0.000 n=10)
any_vs_actual 646.8n ± 1% 642.2n ± 1% -0.70% (p=0.027 n=10)
all_CORS_headers_vs_actual 686.2n ± 1% 766.0n ± 2% +11.64% (p=0.000 n=10)
single_vs_preflight 527.5n ± 1% 497.1n ± 1% -5.74% (p=0.000 n=10)
multiple_vs_preflight 532.7n ± 1% 500.0n ± 1% -6.14% (p=0.000 n=10)
pathological_vs_preflight 533.3n ± 1% 545.3n ± 1% +2.26% (p=0.000 n=10)
many_vs_preflight 493.3n ± 1% 436.9n ± 1% -11.44% (p=0.000 n=10)
any_vs_preflight 522.5n ± 1% 480.8n ± 1% -7.97% (p=0.000 n=10)
ACRH_vs_preflight 488.2n ± 1% 442.4n ± 0% -9.37% (p=0.000 n=10)
all_CORS_headers_vs_preflight 497.8n ± 1% 482.6n ± 1% -3.04% (p=0.000 n=10)
malicious_ACRH_vs_preflight 531.0n ± 1% 478.6n ± 0% -9.88% (p=0.000 n=10)
geomean 577.8n 566.3n -1.98%
│ rs-cors │ jub0bs-cors │
│ B/op │ B/op vs base │
single_vs_actual 1.047Ki ± 0% 1.047Ki ± 0% ~ (p=1.000 n=10) ¹
multiple_vs_actual 1.047Ki ± 0% 1.047Ki ± 0% ~ (p=1.000 n=10) ¹
pathological_vs_actual 1.047Ki ± 0% 1.031Ki ± 0% -1.49% (p=0.000 n=10)
many_vs_actual 1.047Ki ± 0% 1.031Ki ± 0% -1.49% (p=0.000 n=10)
any_vs_actual 1.047Ki ± 0% 1.031Ki ± 0% -1.49% (p=0.000 n=10)
all_CORS_headers_vs_actual 1.062Ki ± 0% 1.078Ki ± 0% +1.47% (p=0.000 n=10)
single_vs_preflight 976.0 ± 0% 944.0 ± 0% -3.28% (p=0.000 n=10)
multiple_vs_preflight 976.0 ± 0% 944.0 ± 0% -3.28% (p=0.000 n=10)
pathological_vs_preflight 960.0 ± 0% 928.0 ± 0% -3.33% (p=0.000 n=10)
many_vs_preflight 960.0 ± 0% 928.0 ± 0% -3.33% (p=0.000 n=10)
any_vs_preflight 976.0 ± 0% 944.0 ± 0% -3.28% (p=0.000 n=10)
ACRH_vs_preflight 968.0 ± 0% 928.0 ± 0% -4.13% (p=0.000 n=10)
all_CORS_headers_vs_preflight 968.0 ± 0% 928.0 ± 0% -4.13% (p=0.000 n=10)
malicious_ACRH_vs_preflight 968.0 ± 0% 928.0 ± 0% -4.13% (p=0.000 n=10)
geomean 1012.9 989.7 -2.29%
¹ all samples are equal
│ rs-cors │ jub0bs-cors │
│ allocs/op │ allocs/op vs base │
single_vs_actual 11.00 ± 0% 11.00 ± 0% ~ (p=1.000 n=10) ¹
multiple_vs_actual 11.00 ± 0% 11.00 ± 0% ~ (p=1.000 n=10) ¹
pathological_vs_actual 12.00 ± 0% 11.00 ± 0% -8.33% (p=0.000 n=10)
many_vs_actual 12.00 ± 0% 11.00 ± 0% -8.33% (p=0.000 n=10)
any_vs_actual 11.00 ± 0% 11.00 ± 0% ~ (p=1.000 n=10) ¹
all_CORS_headers_vs_actual 11.00 ± 0% 12.00 ± 0% +9.09% (p=0.000 n=10)
single_vs_preflight 8.000 ± 0% 7.000 ± 0% -12.50% (p=0.000 n=10)
multiple_vs_preflight 8.000 ± 0% 7.000 ± 0% -12.50% (p=0.000 n=10)
pathological_vs_preflight 9.000 ± 0% 7.000 ± 0% -22.22% (p=0.000 n=10)
many_vs_preflight 9.000 ± 0% 7.000 ± 0% -22.22% (p=0.000 n=10)
any_vs_preflight 8.000 ± 0% 7.000 ± 0% -12.50% (p=0.000 n=10)
ACRH_vs_preflight 9.000 ± 0% 7.000 ± 0% -22.22% (p=0.000 n=10)
all_CORS_headers_vs_preflight 9.000 ± 0% 7.000 ± 0% -22.22% (p=0.000 n=10)
malicious_ACRH_vs_preflight 9.000 ± 0% 7.000 ± 0% -22.22% (p=0.000 n=10)
geomean 9.683 8.549 -11.71%
¹ all samples are equal
For more details about the benchmark labeled "malicious_ACRH_vs_preflight", see rs/cors#170.