Interface/code for running benchmarks on buffers
Setup things so we can remove the time it takes to read the input data.
This commit is contained in:
parent
51570be16c
commit
1cc3247721
@ -100,10 +100,19 @@ type DirectorySummary struct {
|
|||||||
IgnoredErrorCount int `json:"numIgnoredErrors,omitempty"`
|
IgnoredErrorCount int `json:"numIgnoredErrors,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Decoder interface {
|
||||||
|
ManifestDecoder
|
||||||
|
ByteManifestDecoder
|
||||||
|
}
|
||||||
|
|
||||||
type ManifestDecoder interface {
|
type ManifestDecoder interface {
|
||||||
Decode(r io.Reader, gcStats bool) error
|
Decode(r io.Reader, gcStats bool) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ByteManifestDecoder interface {
|
||||||
|
DecodeBytes(data []byte, gcStats bool) error
|
||||||
|
}
|
||||||
|
|
||||||
func PrintMemUsage() {
|
func PrintMemUsage() {
|
||||||
var m runtime.MemStats
|
var m runtime.MemStats
|
||||||
|
|
||||||
|
|||||||
@ -32,6 +32,14 @@ func (d JsonParser) Decode(r io.Reader, gcStats bool) error {
|
|||||||
return parseManifestData(data, gcStats)
|
return parseManifestData(data, gcStats)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d JsonParser) DecodeBytes(data []byte, gcStats bool) error {
|
||||||
|
if gcStats {
|
||||||
|
common.PrintMemUsage()
|
||||||
|
}
|
||||||
|
|
||||||
|
return parseManifestData(data, gcStats)
|
||||||
|
}
|
||||||
|
|
||||||
func parseManifestData(data []byte, gcStats bool) error {
|
func parseManifestData(data []byte, gcStats bool) error {
|
||||||
if gcStats {
|
if gcStats {
|
||||||
common.PrintMemUsage()
|
common.PrintMemUsage()
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package decoder
|
package decoder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@ -10,9 +11,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
_ common.ManifestDecoder = Array{}
|
_ common.ManifestDecoder = Array{}
|
||||||
_ common.ManifestDecoder = ArrayFull{}
|
_ common.ByteManifestDecoder = Array{}
|
||||||
_ common.ManifestDecoder = Map{}
|
_ common.ManifestDecoder = ArrayFull{}
|
||||||
|
_ common.ByteManifestDecoder = ArrayFull{}
|
||||||
|
_ common.ManifestDecoder = Map{}
|
||||||
|
_ common.ByteManifestDecoder = Map{}
|
||||||
)
|
)
|
||||||
|
|
||||||
type Array struct{}
|
type Array struct{}
|
||||||
@ -22,6 +26,13 @@ func (d Array) Decode(r io.Reader, gcStats bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d Array) DecodeBytes(data []byte, gcStats bool) error {
|
||||||
|
r := bytes.NewReader(data)
|
||||||
|
_, err := DecodeManifestArray(r)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func DecodeManifestArray(r io.Reader) (common.Manifest, error) {
|
func DecodeManifestArray(r io.Reader) (common.Manifest, error) {
|
||||||
var (
|
var (
|
||||||
dec = json.NewDecoder(r)
|
dec = json.NewDecoder(r)
|
||||||
@ -78,6 +89,13 @@ func (d ArrayFull) Decode(r io.Reader, gcStats bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d ArrayFull) DecodeBytes(data []byte, gcStats bool) error {
|
||||||
|
r := bytes.NewReader(data)
|
||||||
|
_, err := d.decodeManifestArray(r)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (d ArrayFull) decodeManifestArray(r io.Reader) (common.Manifest, error) {
|
func (d ArrayFull) decodeManifestArray(r io.Reader) (common.Manifest, error) {
|
||||||
var (
|
var (
|
||||||
dec = json.NewDecoder(r)
|
dec = json.NewDecoder(r)
|
||||||
@ -205,6 +223,13 @@ func (d Map) Decode(r io.Reader, gcStats bool) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d Map) DecodeBytes(data []byte, gcStats bool) error {
|
||||||
|
r := bytes.NewReader(data)
|
||||||
|
_, err := d.decodeManifestArray(r)
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (d Map) decodeManifestArray(r io.Reader) (common.Manifest, error) {
|
func (d Map) decodeManifestArray(r io.Reader) (common.Manifest, error) {
|
||||||
var (
|
var (
|
||||||
dec = json.NewDecoder(r)
|
dec = json.NewDecoder(r)
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package decoder
|
package decoder
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
@ -23,3 +24,15 @@ func (d Stdlib) Decode(r io.Reader, gcStats bool) error {
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (d Stdlib) DecodeBytes(data []byte, gcStats bool) error {
|
||||||
|
r := bytes.NewReader(data)
|
||||||
|
dec := json.NewDecoder(r)
|
||||||
|
output := common.Manifest{}
|
||||||
|
|
||||||
|
if err := dec.Decode(&output); err != nil {
|
||||||
|
return errors.Wrap(err, "decoding input")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user