generated from ipfs/ipfs-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ipfs/go-merkledag#67 from ipfs/feat/ipld-in-ipfs
Use IPLD-prime: target merge branch This commit was moved from ipfs/go-merkledag@8794146
- Loading branch information
Showing
7 changed files
with
513 additions
and
133 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package merkledag_test | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"testing" | ||
|
||
cid "github.com/ipfs/go-cid" | ||
ipld "github.com/ipfs/go-ipld-format" | ||
"github.com/ipfs/go-merkledag" | ||
) | ||
|
||
var benchInput []byte | ||
|
||
func init() { | ||
someData := bytes.Repeat([]byte("some plaintext data\n"), 10) | ||
// make a test CID -- doesn't matter just to add as a link | ||
someCid, _ := cid.Cast([]byte{1, 85, 0, 5, 0, 1, 2, 3, 4}) | ||
|
||
node := &merkledag.ProtoNode{} | ||
node.SetData(someData) | ||
for i := 0; i < 10; i++ { | ||
node.AddRawLink(fmt.Sprintf("%d", i), &ipld.Link{ | ||
Size: 10, | ||
Cid: someCid, | ||
}) | ||
} | ||
|
||
enc, err := node.EncodeProtobuf(true) | ||
if err != nil { | ||
panic(err) | ||
} | ||
benchInput = enc | ||
} | ||
|
||
func BenchmarkRoundtrip(b *testing.B) { | ||
b.ReportAllocs() | ||
b.RunParallel(func(pb *testing.PB) { | ||
for pb.Next() { | ||
node, err := merkledag.DecodeProtobuf(benchInput) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
|
||
enc, err := node.EncodeProtobuf(true) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
_ = enc | ||
} | ||
}) | ||
} |
Oops, something went wrong.