yggdrasil-go/misc/tests/wire-test.go

41 lines
1.1 KiB
Go
Raw Permalink Normal View History

2017-12-28 22:16:20 -06:00
package main
import "wire"
import "fmt"
import "time"
func main() {
2018-01-04 22:37:51 +00:00
for idx := 0; idx < 64; idx++ {
num := uint64(1) << uint(idx)
encoded := make([]byte, 10)
length := wire.Encode_uint64(num, encoded)
decoded, _ := wire.Decode_uint64(encoded[:length])
if decoded != num {
panic(fmt.Sprintf("%d != %d", decoded, num))
}
}
const count = 1000000
start := time.Now()
encoded := make([]byte, 10)
//num := ^uint64(0) // Longest possible value for full uint64 range
num := ^uint64(0) >> 1 // Largest positive int64 (real use case)
//num := uint64(0) // Shortest possible value, most will be of this length
length := wire.Encode_uint64(num, encoded)
for idx := 0; idx < count; idx++ {
wire.Encode_uint64(num, encoded)
}
timed := time.Since(start)
fmt.Println("Ops:", count/timed.Seconds())
fmt.Println("Time:", timed.Nanoseconds()/count)
2017-12-28 22:16:20 -06:00
2018-01-04 22:37:51 +00:00
encoded = encoded[:length]
start = time.Now()
for idx := 0; idx < count; idx++ {
wire.Decode_uint64(encoded)
}
timed = time.Since(start)
fmt.Println("Ops:", count/timed.Seconds())
fmt.Println("Time:", timed.Nanoseconds()/count)
2017-12-28 22:16:20 -06:00
}