mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
common/embed: add a benchmark for reading from embed.zip
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Go toolchain / Update Go toolchain (push) Has been cancelled
Some checks failed
CI / 🤖 Check dependabot status (push) Has been cancelled
CI / 🐧 Test on Linux (${{ github.ref_type == 'tag' }}, misc) (push) Has been cancelled
CI / 🐧 Test on Linux (coverage) (push) Has been cancelled
CI / 🐧 Test on Linux (regular) (push) Has been cancelled
CI / ❄️ Build on Nix (push) Has been cancelled
CI / 🍏 Build and test on macOS (push) Has been cancelled
CI / 🧪 End-to-end testing (push) Has been cancelled
CI / 🔍 Upload code coverage (push) Has been cancelled
CI / 🔬 Test only Go (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 20) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 22) (push) Has been cancelled
CI / 🔬 Test only JS (${{ needs.dependabot.outputs.package-ecosystem }}, 24) (push) Has been cancelled
CI / ⚖️ Check licenses (push) Has been cancelled
CI / 🐋 Build Docker images (push) Has been cancelled
CI / 🐋 Tag Docker images (push) Has been cancelled
CI / 🚀 Publish release (push) Has been cancelled
Update Go toolchain / Update Go toolchain (push) Has been cancelled
This is slower, but it seems reasonable: ``` goos: linux goarch: amd64 pkg: akvorado/common/embed cpu: AMD Ryzen 5 5600X 6-Core Processor BenchmarkData/compressed-12 2262 526553 ns/op 610 B/op 10 allocs/op BenchmarkData/uncompressed-12 9482 123175 ns/op 0 B/op 0 allocs/op ```
This commit is contained in:
@@ -1,21 +1,26 @@
|
||||
// SPDX-FileCopyrightText: 2025 Free Mobile
|
||||
// SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
package embed_test
|
||||
package embed
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"akvorado/common/embed"
|
||||
"akvorado/common/helpers"
|
||||
)
|
||||
|
||||
func TestData(t *testing.T) {
|
||||
f, err := embed.Data().Open("orchestrator/clickhouse/data/protocols.csv")
|
||||
f, err := Data().Open("orchestrator/clickhouse/data/protocols.csv")
|
||||
if err != nil {
|
||||
t.Fatalf("Open() error:\n%+v", err)
|
||||
}
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
t.Fatalf("Close() error:\n%+v", err)
|
||||
}
|
||||
}()
|
||||
expected := "proto,name,description"
|
||||
got := make([]byte, len(expected))
|
||||
_, err = io.ReadFull(f, got)
|
||||
@@ -26,3 +31,21 @@ func TestData(t *testing.T) {
|
||||
t.Fatalf("ReadFull() (-got, +want):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkData(b *testing.B) {
|
||||
const amount = 64 * 1024 * 1024
|
||||
got := make([]byte, amount)
|
||||
b.Run("compressed", func(b *testing.B) {
|
||||
for b.Loop() {
|
||||
f, _ := Data().Open("orchestrator/clickhouse/data/tcp.csv")
|
||||
_, _ = io.ReadFull(f, got)
|
||||
f.Close()
|
||||
}
|
||||
})
|
||||
b.Run("uncompressed", func(b *testing.B) {
|
||||
for b.Loop() {
|
||||
copy(got, embeddedZip)
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user