Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-11-09 23:59:16 -05:00
pkg-proxy/internal/handler/npm_rewrite_bench_test.go
Simon Chrzanowski d58b07b2a7 Skip discarded npm packument values with jsontext
ScanPackument and LookupVersion read with a jsontext.Decoder, skipping
values they don't keep with SkipValue and reading the one LookupVersion
returns with ReadValue, instead of decoding each into a json.RawMessage.
Repeated names and invalid UTF-8 are still accepted as encoding/json
accepts them. Go 1.27 is now required, for encoding/json/jsontext.

Benchmarks for both use the 5,000-version packument the handler benchmarks
build, now shared in internal/metadata/npm/npmbench.
2026-11-07 18:02:59 +01:00

30 lines
652 B
Go

package handler
import (
"testing"
"github.com/git-pkgs/proxy/internal/metadata/npm/npmbench"
)
func BenchmarkNPMRewriteMetadata(b *testing.B) {
body := npmbench.Packument(5000)
h := &NPMHandler{proxy: testProxy(), proxyURL: "http://proxy.example"}
b.SetBytes(int64(len(body)))
b.ReportAllocs()
for b.Loop() {
if _, _, err := h.rewriteMetadataKeeping("big", body); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkNPMVersionTarball(b *testing.B) {
body := npmbench.Packument(5000)
b.SetBytes(int64(len(body)))
b.ReportAllocs()
for b.Loop() {
if npmVersionTarball(body, "1.0.2500") == "" {
b.Fatal("tarball not found")
}
}
}