Skip to content

Commit

Permalink
tests: Implement bench for List (#687)
Browse files Browse the repository at this point in the history
* tests: Implement bench for List

Signed-off-by: Xuanwo <github@xuanwo.io>

* Update storager_bench_test.go

* tests: Fix format

Signed-off-by: Xuanwo <github@xuanwo.io>
  • Loading branch information
Xuanwo authored Jul 26, 2021
1 parent 29366c6 commit b6e9d61
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
8 changes: 7 additions & 1 deletion tests/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ type Storage struct {
defaultPairs DefaultStoragePairs
features StorageFeatures

objects []*Object

UnimplementedCopier
UnimplementedFetcher
UnimplementedMover
Expand Down Expand Up @@ -53,7 +55,11 @@ func (s *Storage) fetch(ctx context.Context, path string, url string, opt pairSt
}

func (s *Storage) list(ctx context.Context, path string, opt pairStorageList) (oi *ObjectIterator, err error) {
panic("not implemented")
fn := NextObjectFunc(func(ctx context.Context, page *ObjectPage) error {
page.Data = s.objects
return nil
})
return NewObjectIterator(ctx, fn, nil), nil
}

func (s *Storage) listMultipart(ctx context.Context, o *Object, opt pairStorageListMultipart) (pi *PartIterator, err error) {
Expand Down
29 changes: 28 additions & 1 deletion tests/storager_bench_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package tests

import "testing"
import (
"context"
"testing"

"github.com/beyondstorage/go-storage/v4/types"
)

func BenchmarkStorage_Stat(b *testing.B) {
s, err := NewStorager()
Expand All @@ -12,3 +17,25 @@ func BenchmarkStorage_Stat(b *testing.B) {
_, _ = s.Stat("abc")
}
}

func BenchmarkStorage_List(b *testing.B) {
ctx := context.TODO()

var ob []*types.Object
for i := 0; i < 1024; i++ {
ob = append(ob, &types.Object{})
}

s := &Storage{
objects: ob,
}

it, err := s.list(ctx, "", pairStorageList{})
if err != nil {
b.Fatal(err)
}

for i := 0; i < b.N; i++ {
_, _ = it.Next()
}
}

0 comments on commit b6e9d61

Please sign in to comment.