MCPcopy
hub / github.com/cbeuw/Cloak / BenchmarkRecvDataFromRemote

Function BenchmarkRecvDataFromRemote

internal/multiplex/session_test.go:535–580  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

533}
534
535func BenchmarkRecvDataFromRemote(b *testing.B) {
536 testPayload := make([]byte, testPayloadLen)
537 rand.Read(testPayload)
538 f := Frame{
539 1,
540 0,
541 0,
542 testPayload,
543 }
544
545 var sessionKey [32]byte
546 rand.Read(sessionKey[:])
547
548 const maxIter = 500_000 // run with -benchtime 500000x to avoid index out of bounds panic
549 for name, ep := range encryptionMethods {
550 ep := ep
551 b.Run(name, func(b *testing.B) {
552 for seshType, seshConfig := range seshConfigs {
553 b.Run(seshType, func(b *testing.B) {
554 f := f
555 seshConfig.Obfuscator, _ = MakeObfuscator(ep, sessionKey)
556 sesh := MakeSession(0, seshConfig)
557
558 go func() {
559 stream, _ := sesh.Accept()
560 io.Copy(ioutil.Discard, stream)
561 }()
562
563 binaryFrames := [maxIter][]byte{}
564 for i := 0; i < maxIter; i++ {
565 obfsBuf := make([]byte, obfsBufLen)
566 n, _ := sesh.obfuscate(&f, obfsBuf, 0)
567 binaryFrames[i] = obfsBuf[:n]
568 f.Seq++
569 }
570
571 b.SetBytes(int64(len(f.Payload)))
572 b.ResetTimer()
573 for i := 0; i < b.N; i++ {
574 sesh.recvDataFromRemote(binaryFrames[i])
575 }
576 })
577 }
578 })
579 }
580}
581
582func BenchmarkMultiStreamWrite(b *testing.B) {
583 var sessionKey [32]byte

Callers

nothing calls this directly

Calls 6

MakeObfuscatorFunction · 0.85
obfuscateMethod · 0.80
recvDataFromRemoteMethod · 0.80
MakeSessionFunction · 0.70
ReadMethod · 0.45
AcceptMethod · 0.45

Tested by

no test coverage detected