1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-18 05:25:23 +00:00

benchmark pipe

This commit is contained in:
Darien Raymond 2018-11-17 19:47:30 +01:00
parent 27772a75a7
commit b41513f644
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
2 changed files with 22 additions and 1 deletions

View File

@ -120,7 +120,12 @@ func (p *pipe) writeMultiBufferInternal(mb buf.MultiBuffer) error {
return err
}
p.data, _ = buf.MergeMulti(p.data, mb)
if p.data == nil {
p.data = mb
} else {
p.data, _ = buf.MergeMulti(p.data, mb)
}
return nil
}

View File

@ -6,6 +6,7 @@ import (
"testing"
"time"
"v2ray.com/core/common"
"v2ray.com/core/common/buf"
"v2ray.com/core/common/task"
. "v2ray.com/core/transport/pipe"
@ -125,3 +126,18 @@ func TestInterfaces(t *testing.T) {
assert((*Reader)(nil), Implements, (*buf.Reader)(nil))
assert((*Reader)(nil), Implements, (*buf.TimeoutReader)(nil))
}
func BenchmarkPipeReadWrite(b *testing.B) {
reader, writer := New(WithoutSizeLimit())
a := buf.New()
a.Extend(buf.Size)
c := buf.MultiBuffer{a}
b.ResetTimer()
for i := 0; i < b.N; i++ {
common.Must(writer.WriteMultiBuffer(c))
d, err := reader.ReadMultiBuffer()
common.Must(err)
c = d
}
}