Skip to content

Commit 700ebbf

Browse files
authored
Merge pull request #2 from JAicewizard/v3
V3
2 parents 88e0d7c + e3baed1 commit 700ebbf

File tree

21 files changed

+1561
-70
lines changed

21 files changed

+1561
-70
lines changed

README.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ Data is are benchmarks that use Data, map benchmarks just convert the data to a
1515
## quirks
1616
map[interaface{}]interface{} and map[string]interface{} get converted to Data
1717

18-
i7 975k@3.6 ddr3@1596 make bench
19-
```
20-
BenchmarkGobData-8 2000000 7674 ns/op 1420 B/op 29 allocs/op
21-
BenchmarkGobDataDecode-8 5000000 3551 ns/op 783 B/op 23 allocs/op
22-
BenchmarkGobDataEncode-8 2000000 7031 ns/op 637 B/op 6 allocs/op
23-
BenchmarkGobMap-8 500000 34040 ns/op 2140 B/op 82 allocs/op
24-
BenchmarkGobMapDecode-8 1000000 18148 ns/op 1484 B/op 62 allocs/op
25-
BenchmarkGobMapEncode-8 1000000 21973 ns/op 656 B/op 20 allocs/op
18+
r5 3600 make bench
2619
```
20+
BenchmarkV3-12 3577809 3260 ns/op 945 B/op 17 allocs/op
21+
BenchmarkV3Decode-12 4935484 2343 ns/op 624 B/op 17 allocs/op
22+
BenchmarkV3Encode-12 13271485 835 ns/op 343 B/op 0 allocs/op
23+
BenchmarkGobData-12 4368571 2513 ns/op 1491 B/op 27 allocs/op
24+
BenchmarkGobDataDecode-12 5306721 2271 ns/op 784 B/op 23 allocs/op
25+
BenchmarkGobDataEncode-12 8861355 1235 ns/op 700 B/op 4 allocs/op
26+
BenchmarkGobMap-12 869761 13557 ns/op 1916 B/op 68 allocs/op
27+
BenchmarkGobMapDecode-12 1592424 7375 ns/op 1260 B/op 48 allocs/op
28+
BenchmarkGobMapEncode-12 1000000 10094 ns/op 656 B/op 20 allocs/op```
2729
this update consists of a change in benchmarks, dont compare these to the previous benchmarks.

encode.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ package tt
22

33
import (
44
"bytes"
5+
"encoding/binary"
56
"reflect"
67
"runtime"
7-
"encoding/binary"
88

99
v2 "github.com/JAicewizard/tt/v2"
1010
)
1111

1212
const (
1313
version1 = 1
1414
version2 = 2
15+
version3 = 3
1516
)
1617

1718
func Encodev2(d Data, values *bytes.Buffer) {
@@ -29,11 +30,10 @@ func Encodev2(d Data, values *bytes.Buffer) {
2930
})
3031
//this is bigEndian because then it is compatible with version one of tt
3132
var buf [4]byte
32-
binary.BigEndian.PutUint32(buf[:], uint32(tv + 1))
33+
binary.BigEndian.PutUint32(buf[:], uint32(tv+1))
3334
values.Write(buf[:])
3435
}
3536

36-
3737
func encodemapv1(values *bytes.Buffer, d Data, nextValue *v2.Ikeytype) ([]v2.Ikeytype, error) {
3838
createdObjects := make([]v2.Ikeytype, len(d))
3939
i := 0

go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
module github.com/JAicewizard/tt
22

33
go 1.12
4+
5+
require (
6+
github.com/go-test/deep v1.0.5
7+
golang.org/x/tools/gopls v0.3.0-pre1 // indirect
8+
)

go.sum

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
2+
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
3+
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4+
github.com/go-test/deep v1.0.5 h1:AKODKU3pDH1RzZzm6YZu77YWtEAq6uh1rLIAQlay2qc=
5+
github.com/go-test/deep v1.0.5/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
6+
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
7+
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
8+
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
9+
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
10+
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
11+
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
12+
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
13+
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
14+
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
15+
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
16+
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
17+
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
18+
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
19+
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
20+
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
21+
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee h1:WG0RUwxtNT4qqaXX3DPA8zHFNm/D9xaBpxzHt1WcA/E=
22+
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
23+
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
24+
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
25+
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
26+
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
27+
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
28+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
29+
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
30+
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
31+
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
32+
golang.org/x/tools v0.0.0-20200124212728-cb786845cd63 h1:4yhV2N1eQ2GqWTOo3f9Xlyt6BsuDdV30ZTyYYUPXqTQ=
33+
golang.org/x/tools v0.0.0-20200124212728-cb786845cd63/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
34+
golang.org/x/tools/gopls v0.3.0-pre1 h1:Ey2XgcbaZPtPo8X3krMxVGqFzOFChpekN2HlOfHtbR8=
35+
golang.org/x/tools/gopls v0.3.0-pre1/go.mod h1:5ZH8gcmG5mY8TctAXVBFHp+I4YwOuqJxjxvoacUX8Nc=
36+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898 h1:/atklqdjdhuosWIl6AIbOeHJjicWYPqR9bpxqxYG2pA=
37+
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
38+
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
39+
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
40+
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
41+
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
42+
honnef.co/go/tools v0.0.1-2019.2.3 h1:3JgtbtFHMiCmsznwGVTUWbgGov+pVqnlf1dEJTNAXeM=
43+
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
44+
mvdan.cc/xurls/v2 v2.1.0 h1:KaMb5GLhlcSX+e+qhbRJODnUUBvlw01jt4yrjFIHAuA=
45+
mvdan.cc/xurls/v2 v2.1.0/go.mod h1:5GrSd9rOnKOpZaji1OZLYL/yeAAtGDlo/cFe+8K5n8E=

makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
alloc:
2-
go test -bench=BenchmarkGobData -c
3-
env GODEBUG=allocfreetrace=1 ./tt.test -test.run=none -test.bench=BenchmarkGobDataDecode$$ -test.benchtime=10ms 2>trace.log
2+
go test -bench=BenchmarkV3 -c
3+
env GODEBUG=allocfreetrace=1 ./tt.test -test.run=none -test.bench=BenchmarkV3$$ -test.benchtime=10ms 2>trace.log
44

55
bench:
6-
go test -bench=BenchmarkGob -benchtime=10s -benchmem
6+
go test -bench=. -benchtime=10s -benchmem
77

88
shortbench:
9-
go test -bench=BenchmarkGob -benchtime=1s -benchmem
9+
go test -bench=. -benchtime=1s -benchmem

tt.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tt
33
import (
44
"bytes"
55
"errors"
6+
67
v2 "github.com/JAicewizard/tt/v2"
78
)
89

@@ -56,7 +57,7 @@ func RegisterTransmitter(tr Transmitter) error {
5657
func (d Data) GobEncode() ([]byte, error) {
5758
var byt []byte
5859
buf := bytes.NewBuffer(byt)
59-
Encodev2(d, buf)
60+
Encodev3(d, buf)
6061
return buf.Bytes(), nil
6162
}
6263

@@ -72,4 +73,4 @@ func (d *Data) GobDecode(data []byte) error {
7273
return Decodev2(data[1:], d)
7374
}
7475
return nil
75-
}
76+
}

0 commit comments

Comments
 (0)