mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 22:25:07 +03:00
first code/readme/license commit
This commit is contained in:
parent
35852be36d
commit
d7e6d814a0
60 changed files with 9768 additions and 2 deletions
39
misc/tests/wire-test.go
Normal file
39
misc/tests/wire-test.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package main
|
||||
|
||||
import "wire"
|
||||
import "fmt"
|
||||
|
||||
import "time"
|
||||
|
||||
func main() {
|
||||
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)
|
||||
|
||||
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)
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue