github.com/keltia/go-ipfs@v0.3.8-0.20150909044612-210793031c63/blockservice/worker/bench_worker_test.go (about) 1 package worker 2 3 import ( 4 "testing" 5 6 ds "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore" 7 dssync "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-datastore/sync" 8 blocks "github.com/ipfs/go-ipfs/blocks" 9 blockstore "github.com/ipfs/go-ipfs/blocks/blockstore" 10 "github.com/ipfs/go-ipfs/exchange/offline" 11 ) 12 13 func BenchmarkHandle10KBlocks(b *testing.B) { 14 bstore := blockstore.NewBlockstore(dssync.MutexWrap(ds.NewMapDatastore())) 15 var testdata []*blocks.Block 16 for i := 0; i < 10000; i++ { 17 testdata = append(testdata, blocks.NewBlock([]byte(string(i)))) 18 } 19 b.ResetTimer() 20 b.SetBytes(10000) 21 for i := 0; i < b.N; i++ { 22 23 b.StopTimer() 24 w := NewWorker(offline.Exchange(bstore), Config{ 25 NumWorkers: 1, 26 ClientBufferSize: 0, 27 WorkerBufferSize: 0, 28 }) 29 b.StartTimer() 30 31 for _, block := range testdata { 32 if err := w.HasBlock(block); err != nil { 33 b.Fatal(err) 34 } 35 } 36 37 b.StopTimer() 38 w.Close() 39 b.StartTimer() 40 41 } 42 }