mirror of
https://github.com/git-pkgs/proxy.git
synced 2026-11-09 15:49:16 -05:00
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.
30 lines
652 B
Go
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")
|
|
}
|
|
}
|
|
}
|