From 6af3757136eaf25caeafc7d9f74e0ed51834422b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Sat, 23 Dec 2023 15:18:48 +0100 Subject: [PATCH] treed: 512M bench --- provider/lpproof/treed_build_test.go | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/provider/lpproof/treed_build_test.go b/provider/lpproof/treed_build_test.go index fe020ebb7..5fd28bbd3 100644 --- a/provider/lpproof/treed_build_test.go +++ b/provider/lpproof/treed_build_test.go @@ -6,6 +6,7 @@ import ( "fmt" "github.com/filecoin-project/go-state-types/abi" "github.com/stretchr/testify/require" + "io/ioutil" "os" "path/filepath" "testing" @@ -262,3 +263,37 @@ func BenchmarkHashChunk(b *testing.B) { _ = data[1] } } + +func BenchmarkBuildTreeD512M(b *testing.B) { + const dataSize = 512 * 1024 * 1024 // 512 MiB + + // Generate 512 MiB of random data + data := make([]byte, dataSize) + if _, err := rand.Read(data); err != nil { + b.Fatalf("Failed to generate random data: %v", err) + } + + b.SetBytes(int64(dataSize)) // Set the number of bytes for the benchmark + + for i := 0; i < b.N; i++ { + // Create a temporary file for each iteration + tempFile, err := ioutil.TempFile("", "tree.dat") + if err != nil { + b.Fatalf("Failed to create temporary file: %v", err) + } + tempFilePath := tempFile.Name() + tempFile.Close() + + b.StartTimer() // Start the timer for the BuildTreeD operation + + _, err = BuildTreeD(bytes.NewReader(data), tempFilePath, dataSize) + if err != nil { + b.Fatalf("BuildTreeD failed: %v", err) + } + + b.StopTimer() // Stop the timer after BuildTreeD completes + + // Clean up the temporary file + os.Remove(tempFilePath) + } +}