forked from heetch/avro
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also speed up SingleDecoder a lot (we'd forgotten to cache the compile results) and unmarshaling in general (the debugf calls were really slowing things down). Here are the new benchmark results after these changes have been made: ``` BenchmarkMarshal-4 10628875 551 ns/op 240 B/op 4 allocs/op BenchmarkSingleDecoderUnmarshal-4 3596359 1619 ns/op 272 B/op 14 allocs/op ```
- Loading branch information
Showing
8 changed files
with
174 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package avro_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
qt "github.com/frankban/quicktest" | ||
"github.com/heetch/avro" | ||
) | ||
|
||
func BenchmarkMarshal(b *testing.B) { | ||
type R struct { | ||
A *string | ||
B *string | ||
C []int | ||
} | ||
type T struct { | ||
R R | ||
} | ||
x := T{ | ||
R: R{ | ||
A: newString("hello"), | ||
B: newString("goodbye"), | ||
C: []int{1, 3, 1 << 20}, | ||
}, | ||
} | ||
for i := 0; i < b.N; i++ { | ||
_, _, err := avro.Marshal(x) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func BenchmarkSingleDecoderUnmarshal(b *testing.B) { | ||
c := qt.New(b) | ||
type R struct { | ||
A *string | ||
B *string | ||
C []int | ||
} | ||
type T struct { | ||
R R | ||
} | ||
at, err := avro.TypeOf(T{}) | ||
c.Assert(err, qt.Equals, nil) | ||
r := memRegistry{ | ||
1: at.String(), | ||
} | ||
enc := avro.NewSingleEncoder(r, nil) | ||
ctx := context.Background() | ||
data, err := enc.Marshal(ctx, T{ | ||
R: R{ | ||
A: newString("hello"), | ||
B: newString("goodbye"), | ||
C: []int{1, 3, 1 << 20}, | ||
}, | ||
}) | ||
c.Assert(err, qt.Equals, nil) | ||
|
||
dec := avro.NewSingleDecoder(r, nil) | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
var x T | ||
_, err := dec.Unmarshal(ctx, data, &x) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
} | ||
|
||
func newString(s string) *string { | ||
return &s | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters