mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-12 03:21:33 +00:00
Reflists are basically stored as arrays of strings, which are quite space-efficient in MessagePack. Thus, using zero-copy decoding results in nice performance and memory savings, because the overhead of separate allocations ends up far exceeding the overhead of the original slice. With the included benchmark run for 20s with -benchmem, the runtime, memory usage, and allocations go from ~740us/op, ~192KiB/op, and 4100 allocs/op to ~240us/op, ~97KiB/op, and 13 allocs/op, respectively. Signed-off-by: Ryan Gonzalez <ryan.gonzalez@collabora.com>
48 lines
806 B
Go
48 lines
806 B
Go
package deb
|
|
|
|
import (
|
|
"fmt"
|
|
"sort"
|
|
"testing"
|
|
)
|
|
|
|
func BenchmarkReflistSimpleMerge(b *testing.B) {
|
|
const count = 4096
|
|
|
|
l := NewPackageRefList()
|
|
r := NewPackageRefList()
|
|
|
|
for i := 0; i < count; i++ {
|
|
if i%2 == 0 {
|
|
l.Refs = append(l.Refs, []byte(fmt.Sprintf("Pamd64 pkg%d %d", i, i)))
|
|
} else {
|
|
r.Refs = append(r.Refs, []byte(fmt.Sprintf("Pamd64 pkg%d %d", i, i)))
|
|
}
|
|
}
|
|
|
|
sort.Sort(l)
|
|
sort.Sort(r)
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
l.Merge(r, false, true)
|
|
}
|
|
}
|
|
|
|
func BenchmarkReflistDecode(b *testing.B) {
|
|
const count = 4096
|
|
|
|
r := NewPackageRefList()
|
|
for i := 0; i < count; i++ {
|
|
r.Refs = append(r.Refs, []byte(fmt.Sprintf("Pamd64 pkg%d %d", i, i)))
|
|
}
|
|
|
|
sort.Sort(r)
|
|
data := r.Encode()
|
|
|
|
b.ResetTimer()
|
|
for i := 0; i < b.N; i++ {
|
|
(&PackageRefList{}).Decode(data)
|
|
}
|
|
}
|