Skip to content

Commit 63c977e

Browse files
committed
Expand generated API
1 parent 58fbd38 commit 63c977e

22 files changed

+2200
-1059
lines changed

README.md

+15-15
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,20 @@ go test -benchmem -bench '.*' ./benchmark
122122
goos: darwin
123123
goarch: amd64
124124
pkg: github.com/skycoin/skyencoder/benchmark
125-
BenchmarkEncodeSize-8 300000000 5.69 ns/op 0 B/op 0 allocs/op
126-
BenchmarkCipherEncodeSize-8 1000000 1371 ns/op 120 B/op 15 allocs/op
127-
BenchmarkEncode-8 10000000 127 ns/op 0 B/op 0 allocs/op
128-
BenchmarkEncodeSizePlusEncode-8 10000000 177 ns/op 112 B/op 1 allocs/op
129-
BenchmarkCipherEncode-8 500000 3270 ns/op 384 B/op 32 allocs/op
130-
BenchmarkDecode-8 5000000 364 ns/op 112 B/op 9 allocs/op
131-
BenchmarkCipherDecode-8 1000000 2202 ns/op 456 B/op 27 allocs/op
132-
BenchmarkEncodeSizeSignedBlock-8 50000000 25.1 ns/op 0 B/op 0 allocs/op
133-
BenchmarkCipherEncodeSizeSignedBlock-8 200000 7617 ns/op 600 B/op 75 allocs/op
134-
BenchmarkEncodeSignedBlock-8 3000000 423 ns/op 0 B/op 0 allocs/op
135-
BenchmarkEncodeSizePlusEncodeSignedBlock-8 2000000 742 ns/op 1792 B/op 1 allocs/op
136-
BenchmarkCipherEncodeSignedBlock-8 100000 18004 ns/op 4080 B/op 185 allocs/op
137-
BenchmarkDecodeSignedBlock-8 1000000 1029 ns/op 1648 B/op 10 allocs/op
138-
BenchmarkCipherDecodeSignedBlock-8 100000 12466 ns/op 5448 B/op 130 allocs/op
125+
BenchmarkEncodeSize-8 200000000 6.33 ns/op 0 B/op 0 allocs/op
126+
BenchmarkCipherEncodeSize-8 1000000 1488 ns/op 128 B/op 16 allocs/op
127+
BenchmarkEncodeToBuffer-8 10000000 133 ns/op 0 B/op 0 allocs/op
128+
BenchmarkEncode-8 10000000 189 ns/op 112 B/op 1 allocs/op
129+
BenchmarkCipherEncode-8 500000 3103 ns/op 400 B/op 34 allocs/op
130+
BenchmarkDecode-8 5000000 375 ns/op 120 B/op 10 allocs/op
131+
BenchmarkCipherDecode-8 500000 2425 ns/op 472 B/op 29 allocs/op
132+
BenchmarkEncodeSizeSignedBlock-8 50000000 25.0 ns/op 0 B/op 0 allocs/op
133+
BenchmarkCipherEncodeSizeSignedBlock-8 200000 8125 ns/op 600 B/op 75 allocs/op
134+
BenchmarkEncodeSignedBlockToBuffer-8 3000000 418 ns/op 0 B/op 0 allocs/op
135+
BenchmarkEncodeSignedBlock-8 2000000 721 ns/op 1792 B/op 1 allocs/op
136+
BenchmarkCipherEncodeSignedBlock-8 100000 19673 ns/op 4080 B/op 185 allocs/op
137+
BenchmarkDecodeSignedBlock-8 1000000 1002 ns/op 1648 B/op 10 allocs/op
138+
BenchmarkCipherDecodeSignedBlock-8 100000 13919 ns/op 5448 B/op 130 allocs/op
139139
PASS
140-
ok github.com/skycoin/skyencoder/benchmark 24.378s
140+
ok github.com/skycoin/skyencoder/benchmark 24.198s
141141
```

benchmark/benchmark_struct_skyencoder.go

+55-24
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benchmark/benchmark_test.go

+11-16
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,18 @@ func TestEncodeEqual(t *testing.T) {
7777

7878
data1 := make([]byte, EncodeSizeBenchmarkStruct(bs))
7979

80-
if err := EncodeBenchmarkStruct(data1, bs); err != nil {
80+
if err := EncodeBenchmarkStructToBuffer(data1, bs); err != nil {
8181
t.Fatal(err)
8282
}
8383

8484
data2 := encoder.Serialize(bs)
8585

8686
if !bytes.Equal(data1, data2) {
87-
t.Fatal("EncodeBenchmarkStruct() != encoder.Serialize()")
87+
t.Fatal("EncodeBenchmarkStructToBuffer() != encoder.Serialize()")
8888
}
8989
}
9090

91-
func BenchmarkEncode(b *testing.B) {
91+
func BenchmarkEncodeToBuffer(b *testing.B) {
9292
bs := newBenchmarkStruct()
9393

9494
n := EncodeSizeBenchmarkStruct(bs)
@@ -98,20 +98,17 @@ func BenchmarkEncode(b *testing.B) {
9898
b.ResetTimer()
9999

100100
for i := 0; i < b.N; i++ {
101-
EncodeBenchmarkStruct(buf[:], bs)
101+
EncodeBenchmarkStructToBuffer(buf[:], bs)
102102
}
103103
}
104104

105-
func BenchmarkEncodeSizePlusEncode(b *testing.B) {
106-
// Performs EncodeSize + Encode to better mimic encoder.Serialize which will do a size calculation internally
105+
func BenchmarkEncode(b *testing.B) {
107106
bs := newBenchmarkStruct()
108107

109108
b.ResetTimer()
110109

111110
for i := 0; i < b.N; i++ {
112-
n := EncodeSizeBenchmarkStruct(bs)
113-
buf := make([]byte, n)
114-
EncodeBenchmarkStruct(buf[:], bs)
111+
EncodeBenchmarkStruct(bs)
115112
}
116113
}
117114

@@ -144,7 +141,7 @@ func TestDecodeEqual(t *testing.T) {
144141
var bs1 BenchmarkStruct
145142
if n, err := DecodeBenchmarkStruct(data1, &bs1); err != nil {
146143
t.Fatal(err)
147-
} else if n != len(data1) {
144+
} else if n != uint64(len(data1)) {
148145
t.Fatalf("DecodeBenchmarkStruct n should be %d, is %d", len(data1), n)
149146
}
150147

@@ -299,7 +296,7 @@ func BenchmarkCipherEncodeSizeSignedBlock(b *testing.B) {
299296
}
300297
}
301298

302-
func BenchmarkEncodeSignedBlock(b *testing.B) {
299+
func BenchmarkEncodeSignedBlockToBuffer(b *testing.B) {
303300
bs := newSignedBlock()
304301

305302
n := EncodeSizeSignedBlock(bs)
@@ -309,20 +306,18 @@ func BenchmarkEncodeSignedBlock(b *testing.B) {
309306
b.ResetTimer()
310307

311308
for i := 0; i < b.N; i++ {
312-
EncodeSignedBlock(buf[:], bs)
309+
EncodeSignedBlockToBuffer(buf[:], bs)
313310
}
314311
}
315312

316-
func BenchmarkEncodeSizePlusEncodeSignedBlock(b *testing.B) {
313+
func BenchmarkEncodeSignedBlock(b *testing.B) {
317314
// Performs EncodeSize + Encode to better mimic encoder.Serialize which will do a size calculation internally
318315
bs := newSignedBlock()
319316

320317
b.ResetTimer()
321318

322319
for i := 0; i < b.N; i++ {
323-
n := EncodeSizeSignedBlock(bs)
324-
buf := make([]byte, n)
325-
EncodeSignedBlock(buf[:], bs)
320+
EncodeSignedBlock(bs)
326321
}
327322
}
328323

0 commit comments

Comments
 (0)