mirror of
https://github.com/bluenviron/mediamtx.git
synced 2025-12-20 02:00:05 -08:00
rtmp: improve performance
reuse existing structs instead of allocating them during every read()
This commit is contained in:
parent
4f023b25e8
commit
0db2d3eb8c
3 changed files with 91 additions and 66 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package rtmp
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"net"
|
||||
"net/url"
|
||||
"testing"
|
||||
|
|
@ -1210,3 +1211,32 @@ func TestWriteTracks(t *testing.T) {
|
|||
Payload: []byte{0x12, 0x10},
|
||||
}, msg)
|
||||
}
|
||||
|
||||
func BenchmarkRead(b *testing.B) {
|
||||
var buf bytes.Buffer
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
buf.Write([]byte{
|
||||
7, 0, 0, 23, 0, 0, 98, 8,
|
||||
0, 0, 0, 64, 175, 1, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4, 1, 2,
|
||||
3, 4, 1, 2, 3, 4,
|
||||
})
|
||||
}
|
||||
|
||||
conn := NewConn(&buf)
|
||||
|
||||
for n := 0; n < b.N; n++ {
|
||||
conn.ReadMessage()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue