-
-
Notifications
You must be signed in to change notification settings - Fork 628
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/erigontech/torrent
- Loading branch information
Showing
18 changed files
with
915 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package torrent | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
|
||
"github.com/dustin/go-humanize" | ||
|
||
pp "github.com/anacrolix/torrent/peer_protocol" | ||
) | ||
|
||
func PieceMsg(length int64) pp.Message { | ||
return pp.Message{ | ||
Type: pp.Piece, | ||
Index: pp.Integer(0), | ||
Begin: pp.Integer(0), | ||
Piece: make([]byte, length), | ||
} | ||
} | ||
|
||
var benchmarkPieceLengths = []int{defaultChunkSize, 1 << 20, 4 << 20, 8 << 20} | ||
|
||
func runBenchmarkWriteToBuffer(b *testing.B, length int64) { | ||
writer := &peerConnMsgWriter{ | ||
writeBuffer: &bytes.Buffer{}, | ||
} | ||
msg := PieceMsg(length) | ||
|
||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
//b.StopTimer() | ||
writer.writeBuffer.Reset() | ||
//b.StartTimer() | ||
writer.writeToBuffer(msg) | ||
} | ||
} | ||
|
||
func BenchmarkWritePieceMsg(b *testing.B) { | ||
for _, length := range benchmarkPieceLengths { | ||
b.Run(humanize.IBytes(uint64(length)), func(b *testing.B) { | ||
b.Run("ToBuffer", func(b *testing.B) { | ||
b.SetBytes(int64(length)) | ||
runBenchmarkWriteToBuffer(b, int64(length)) | ||
}) | ||
b.Run("MarshalBinary", func(b *testing.B) { | ||
b.SetBytes(int64(length)) | ||
runBenchmarkMarshalBinaryWrite(b, int64(length)) | ||
}) | ||
}) | ||
} | ||
} | ||
|
||
func runBenchmarkMarshalBinaryWrite(b *testing.B, length int64) { | ||
writer := &peerConnMsgWriter{ | ||
writeBuffer: &bytes.Buffer{}, | ||
} | ||
msg := PieceMsg(length) | ||
|
||
b.ReportAllocs() | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
//b.StopTimer() | ||
writer.writeBuffer.Reset() | ||
//b.StartTimer() | ||
writer.writeBuffer.Write(msg.MustMarshalBinary()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
go 1.22.0 | ||
go 1.22.2 | ||
|
||
use ( | ||
. | ||
.. | ||
./issue-930 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.