internal/pipewire: benchmarks against Gob and JSON
All checks were successful
Test / Create distribution (push) Successful in 36s
Test / Sandbox (push) Successful in 2m19s
Test / Hakurei (push) Successful in 3m17s
Test / Hpkg (push) Successful in 4m8s
Test / Sandbox (race detector) (push) Successful in 4m15s
Test / Hakurei (race detector) (push) Successful in 5m11s
Test / Flake checks (push) Successful in 1m33s
All checks were successful
Test / Create distribution (push) Successful in 36s
Test / Sandbox (push) Successful in 2m19s
Test / Hakurei (push) Successful in 3m17s
Test / Hpkg (push) Successful in 4m8s
Test / Sandbox (race detector) (push) Successful in 4m15s
Test / Hakurei (race detector) (push) Successful in 5m11s
Test / Flake checks (push) Successful in 1m33s
Performance does not matter for the use case of this library, but it is still interesting to know. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
3d4c7cdd9e
commit
91aaabaa1b
@ -1,8 +1,11 @@
|
|||||||
package pipewire_test
|
package pipewire_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding"
|
"encoding"
|
||||||
|
"encoding/gob"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"io"
|
||||||
"reflect"
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -66,6 +69,83 @@ func (testCases encodingTestCases[V, S]) run(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var benchmarkSample = func() (sample pipewire.CoreInfo) {
|
||||||
|
if err := sample.UnmarshalBinary(samplePWContainer[1][0][1]); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}()
|
||||||
|
|
||||||
|
func BenchmarkMarshal(b *testing.B) {
|
||||||
|
for b.Loop() {
|
||||||
|
if _, err := benchmarkSample.MarshalBinary(); err != nil {
|
||||||
|
b.Fatalf("MarshalBinary: error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkMarshalJSON(b *testing.B) {
|
||||||
|
for b.Loop() {
|
||||||
|
if _, err := json.Marshal(benchmarkSample); err != nil {
|
||||||
|
b.Fatalf("json.Marshal: error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkGobEncode(b *testing.B) {
|
||||||
|
e := gob.NewEncoder(io.Discard)
|
||||||
|
type sampleRaw pipewire.CoreInfo
|
||||||
|
|
||||||
|
for b.Loop() {
|
||||||
|
if err := e.Encode((*sampleRaw)(&benchmarkSample)); err != nil {
|
||||||
|
b.Fatalf("(*gob.Encoder).Encode: error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkUnmarshal(b *testing.B) {
|
||||||
|
var got pipewire.CoreInfo
|
||||||
|
|
||||||
|
for b.Loop() {
|
||||||
|
if err := got.UnmarshalBinary(samplePWContainer[1][0][1]); err != nil {
|
||||||
|
b.Fatalf("UnmarshalBinary: error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkUnmarshalJSON(b *testing.B) {
|
||||||
|
var got pipewire.CoreInfo
|
||||||
|
data, err := json.Marshal(benchmarkSample)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatalf("json.Marshal: error = %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for b.Loop() {
|
||||||
|
if err = json.Unmarshal(data, &got); err != nil {
|
||||||
|
b.Fatalf("json.Unmarshal: error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkGobDecode(b *testing.B) {
|
||||||
|
type sampleRaw pipewire.CoreInfo
|
||||||
|
var buf bytes.Buffer
|
||||||
|
e := gob.NewEncoder(&buf)
|
||||||
|
d := gob.NewDecoder(&buf)
|
||||||
|
|
||||||
|
for b.Loop() {
|
||||||
|
b.StopTimer()
|
||||||
|
if err := e.Encode((*sampleRaw)(&benchmarkSample)); err != nil {
|
||||||
|
b.Fatalf("(*gob.Encoder).Encode: error = %v", err)
|
||||||
|
}
|
||||||
|
b.StartTimer()
|
||||||
|
|
||||||
|
if err := d.Decode(new(sampleRaw)); err != nil {
|
||||||
|
b.Fatalf("(*gob.Encoder).Decode: error = %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// mustMarshalJSON calls [json.Marshal] and returns the result.
|
// mustMarshalJSON calls [json.Marshal] and returns the result.
|
||||||
func mustMarshalJSON(v any) string {
|
func mustMarshalJSON(v any) string {
|
||||||
if data, err := json.Marshal(v); err != nil {
|
if data, err := json.Marshal(v); err != nil {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user