]> Cypherpunks.ru repositories - govpn.git/commitdiff
Fixed benchmark tests
authorSergey Matveev <stargrave@stargrave.org>
Mon, 14 Sep 2015 06:49:25 +0000 (09:49 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Mon, 14 Sep 2015 06:49:25 +0000 (09:49 +0300)
Signed-off-by: Sergey Matveev <stargrave@stargrave.org>
src/govpn/peer_test.go [moved from src/govpn/transport_test.go with 76% similarity]

similarity index 76%
rename from src/govpn/transport_test.go
rename to src/govpn/peer_test.go
index f9f731e7139a825e9ba23f97f4183f4e604a33f8..9bad8c6960a792c1ca41b766289188aa977dc1a0 100644 (file)
@@ -8,7 +8,6 @@ import (
 var (
        peer       *Peer
        plaintext  []byte
-       ready      chan struct{}
        ciphertext []byte
        peerId     *PeerId
        conf       *PeerConf
@@ -25,10 +24,6 @@ func (d Dummy) Write(b []byte) (int, error) {
        return len(b), nil
 }
 
-func (d Dummy) Reorderable() bool {
-       return true
-}
-
 func init() {
        MTU = 1500
        peerId, _ = IDDecode("ffffffffffffffffffffffffffffffff")
@@ -40,30 +35,27 @@ func init() {
        }
        peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
        plaintext = make([]byte, 789)
-       ready = make(chan struct{})
-       go func() {
-               for {
-                       <-ready
-               }
-       }()
 }
 
 func BenchmarkEnc(b *testing.B) {
        b.ResetTimer()
        for i := 0; i < b.N; i++ {
-               peer.NonceOur = 128
-               peer.EthProcess(plaintext, ready)
+               peer.EthProcess(plaintext)
        }
 }
 
 func BenchmarkDec(b *testing.B) {
-       peer.EthProcess(plaintext, ready)
+       peer = newPeer(true, "foo", Dummy{&ciphertext}, conf, new([SSize]byte))
+       peer.EthProcess(plaintext)
        peer = newPeer(true, "foo", Dummy{nil}, conf, new([SSize]byte))
+       orig := make([]byte, len(ciphertext))
+       copy(orig, ciphertext)
        b.ResetTimer()
        for i := 0; i < b.N; i++ {
                peer.nonceBucket0 = make(map[uint64]struct{}, 1)
                peer.nonceBucket1 = make(map[uint64]struct{}, 1)
-               if !peer.PktProcess(ciphertext, Dummy{nil}, ready) {
+               copy(ciphertext, orig)
+               if !peer.PktProcess(ciphertext, Dummy{nil}, true) {
                        b.Fail()
                }
        }