github.com/Synthesix/Sia@v1.3.3-0.20180413141344-f863baeed3ca/types/block_bench_test.go (about) 1 package types 2 3 import ( 4 "io/ioutil" 5 "testing" 6 7 "github.com/Synthesix/Sia/encoding" 8 ) 9 10 // BenchmarkEncodeEmptyBlock benchmarks encoding an empty block. 11 // 12 // i5-4670K, 9a90f86: 48 MB/s 13 // i5-4670K, f8f2df2: 211 MB/s 14 func BenchmarkEncodeEmptyBlock(b *testing.B) { 15 var block Block 16 b.SetBytes(int64(len(encoding.Marshal(block)))) 17 b.ReportAllocs() 18 for i := 0; i < b.N; i++ { 19 block.MarshalSia(ioutil.Discard) 20 } 21 } 22 23 // BenchmarkDecodeEmptyBlock benchmarks decoding an empty block. 24 // 25 // i7-4770, b0b162d: 38 MB/s 26 // i5-4670K, 9a90f86: 55 MB/s 27 // i5-4670K, f8f2df2: 166 MB/s 28 func BenchmarkDecodeEmptyBlock(b *testing.B) { 29 var block Block 30 encodedBlock := encoding.Marshal(block) 31 b.SetBytes(int64(len(encodedBlock))) 32 b.ReportAllocs() 33 for i := 0; i < b.N; i++ { 34 err := encoding.Unmarshal(encodedBlock, &block) 35 if err != nil { 36 b.Fatal(err) 37 } 38 } 39 } 40 41 // BenchmarkEncodeHeavyBlock benchmarks encoding a "heavy" block. 42 // 43 // i5-4670K, f8f2df2: 250 MB/s 44 func BenchmarkEncodeHeavyBlock(b *testing.B) { 45 b.SetBytes(int64(len(encoding.Marshal(heavyBlock)))) 46 b.ReportAllocs() 47 b.ResetTimer() 48 for i := 0; i < b.N; i++ { 49 heavyBlock.MarshalSia(ioutil.Discard) 50 } 51 } 52 53 // BenchmarkDecodeHeavyBlock benchmarks decoding a "heavy" block. 54 // 55 // i5-4670K, f8f2df2: 326 MB/s 56 func BenchmarkDecodeHeavyBlock(b *testing.B) { 57 var block Block 58 encodedBlock := encoding.Marshal(heavyBlock) 59 b.SetBytes(int64(len(encodedBlock))) 60 b.ReportAllocs() 61 b.ResetTimer() 62 for i := 0; i < b.N; i++ { 63 err := encoding.Unmarshal(encodedBlock, &block) 64 if err != nil { 65 b.Fatal(err) 66 } 67 } 68 }