github.com/avahowell/sia@v0.5.1-beta.0.20160524050156-83dcc3d37c94/types/block_bench_test.go (about)

     1  package types
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/NebulousLabs/Sia/encoding"
     7  )
     8  
     9  // BenchmarkEncodeEmptyBlock benchmarks encoding an empty block.
    10  //
    11  // i5-4670K, 9a90f86: 48 MB/s
    12  func BenchmarkEncodeBlock(b *testing.B) {
    13  	var block Block
    14  	b.SetBytes(int64(len(encoding.Marshal(block))))
    15  	for i := 0; i < b.N; i++ {
    16  		encoding.Marshal(block)
    17  	}
    18  }
    19  
    20  // BenchmarkDecodeEmptyBlock benchmarks decoding an empty block.
    21  //
    22  // i7-4770,  b0b162d: 38 MB/s
    23  // i5-4670K, 9a90f86: 55 MB/s
    24  func BenchmarkDecodeEmptyBlock(b *testing.B) {
    25  	var block Block
    26  	encodedBlock := encoding.Marshal(block)
    27  	b.SetBytes(int64(len(encodedBlock)))
    28  	for i := 0; i < b.N; i++ {
    29  		err := encoding.Unmarshal(encodedBlock, &block)
    30  		if err != nil {
    31  			b.Fatal(err)
    32  		}
    33  	}
    34  }