[vegz] Rename to gzep.
This commit is contained in:
parent
a5e79ba175
commit
19030efe9e
4 changed files with 5 additions and 36 deletions
|
@ -1,4 +1,4 @@
|
|||
## vegz [runtime]
|
||||
## gzep [runtime]
|
||||
|
||||
В этой задаче нужно победить бенчмарк, переписав функцию сериализации в `gzip`.
|
||||
|
||||
|
@ -6,14 +6,14 @@
|
|||
```
|
||||
goos: linux
|
||||
goarch: amd64
|
||||
pkg: gitlab.com/slon/shad-go/vegz
|
||||
pkg: gitlab.com/slon/shad-go/gzep
|
||||
cpu: Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
|
||||
BenchmarkEncodeSimple
|
||||
BenchmarkEncodeSimple-8 8307 124841 ns/op 813872 B/op 17 allocs/op
|
||||
BenchmarkEncode
|
||||
BenchmarkEncode-8 2094512 620.0 ns/op 0 B/op 0 allocs/op
|
||||
PASS
|
||||
ok gitlab.com/slon/shad-go/vegz 3.756s
|
||||
ok gitlab.com/slon/shad-go/gzep 3.756s
|
||||
```
|
||||
|
||||
### С чего начать?
|
|
@ -1,6 +1,6 @@
|
|||
//go:build !solution
|
||||
|
||||
package vegz
|
||||
package gzep
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
|
@ -1,4 +1,4 @@
|
|||
package vegz
|
||||
package gzep
|
||||
|
||||
import (
|
||||
"bytes"
|
|
@ -1,31 +0,0 @@
|
|||
//go:build solution
|
||||
|
||||
package vegz
|
||||
|
||||
import (
|
||||
"compress/gzip"
|
||||
"io"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var writerPool = sync.Pool{
|
||||
New: func() interface{} {
|
||||
return new(gzip.Writer)
|
||||
},
|
||||
}
|
||||
|
||||
func Encode(data []byte, w io.Writer) error {
|
||||
ww := writerPool.Get().(*gzip.Writer)
|
||||
defer func() {
|
||||
_ = ww.Close()
|
||||
writerPool.Put(ww)
|
||||
}()
|
||||
|
||||
ww.Reset(w)
|
||||
|
||||
if _, err := ww.Write(data); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return ww.Close()
|
||||
}
|
Loading…
Reference in a new issue