Skip to content

Commit

Permalink
add benchmark for hamt walking
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Steven Allen <steven@stebalien.com>
  • Loading branch information
Stebalien committed Mar 30, 2018
1 parent f1ae13d commit 1907e66
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions unixfs/hamt/hamt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,49 @@ func printDiff(ds ipld.DAGService, a, b *dag.ProtoNode) {
}
}

func BenchmarkHAMTWalk(b *testing.B) {
ctx := context.Background()

ds := mdtest.Mock()
sh, _ := NewShard(ds, 256)
nd, err := sh.Node()
if err != nil {
b.Fatal(err)
}

err = ds.Add(ctx, nd)
if err != nil {
b.Fatal(err)
}
ds.Add(ctx, ft.EmptyDirNode())

s, err := NewHamtFromDag(ds, nd)
if err != nil {
b.Fatal(err)
}

for j := 0; j < 1000; j++ {
err = s.Set(ctx, fmt.Sprintf("%d", j), ft.EmptyDirNode())
if err != nil {
b.Fatal(err)
}
}

for i := 0; i < b.N; i++ {
cnt := 0
err = s.ForEachLink(ctx, func(l *ipld.Link) error {
cnt++
return nil
})
if err != nil {
b.Fatal(err)
}
if cnt < 1000 {
b.Fatal("expected 100 children")
}
}
}

func BenchmarkHAMTSet(b *testing.B) {
ctx := context.Background()

Expand Down

0 comments on commit 1907e66

Please sign in to comment.