Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-kad-dht
Commits
5bc18f62
Commit
5bc18f62
authored
Jun 29, 2019
by
whyrusleeping
Committed by
Steven Allen
Mar 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add benchmark for handleFindPeer
parent
c2631d95
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
0 deletions
+57
-0
handlers_test.go
handlers_test.go
+57
-0
No files found.
handlers_test.go
View file @
5bc18f62
...
...
@@ -2,10 +2,19 @@ package dht
import
(
"bytes"
"context"
"fmt"
"math/rand"
"testing"
"time"
proto
"github.com/gogo/protobuf/proto"
"github.com/libp2p/go-libp2p"
crypto
"github.com/libp2p/go-libp2p-core/crypto"
peer
"github.com/libp2p/go-libp2p-core/peer"
pb
"github.com/libp2p/go-libp2p-kad-dht/pb"
recpb
"github.com/libp2p/go-libp2p-record/pb"
ma
"github.com/multiformats/go-multiaddr"
)
func
TestCleanRecordSigned
(
t
*
testing
.
T
)
{
...
...
@@ -57,3 +66,51 @@ func TestCleanRecord(t *testing.T) {
t
.
Error
(
"failed to clean record"
)
}
}
func
BenchmarkHandleFindPeer
(
b
*
testing
.
B
)
{
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
h
,
err
:=
libp2p
.
New
(
ctx
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
d
,
err
:=
New
(
ctx
,
h
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
rng
:=
rand
.
New
(
rand
.
NewSource
(
150
))
var
peers
[]
peer
.
ID
for
i
:=
0
;
i
<
1000
;
i
++
{
_
,
pubk
,
_
:=
crypto
.
GenerateEd25519Key
(
rng
)
id
,
err
:=
peer
.
IDFromPublicKey
(
pubk
)
if
err
!=
nil
{
panic
(
err
)
}
d
.
routingTable
.
Update
(
id
)
peers
=
append
(
peers
,
id
)
a
,
err
:=
ma
.
NewMultiaddr
(
fmt
.
Sprintf
(
"/ip4/127.0.0.1/tcp/%d"
,
2000
+
i
))
if
err
!=
nil
{
panic
(
err
)
}
d
.
host
.
Peerstore
()
.
AddAddr
(
id
,
a
,
time
.
Minute
*
50
)
}
var
reqs
[]
*
pb
.
Message
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
reqs
=
append
(
reqs
,
&
pb
.
Message
{
Key
:
[]
byte
(
"asdasdasd"
),
})
}
b
.
ReportAllocs
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
d
.
handleFindPeer
(
ctx
,
peers
[
0
],
reqs
[
i
])
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment