github.com/zerosnake0/jzon@v0.0.9-0.20230801092939-1b135cb83f7f/performance_reset_test.go (about) 1 package jzon 2 3 import ( 4 "testing" 5 ) 6 7 func resetTestImpl(it *Iterator) { 8 it.reader = nil 9 it.buffer = nil 10 it.tail = 0 11 12 it.capture = false 13 it.offset = 0 14 it.head = 0 15 it.lastEfaceOffset = 0 16 it.lastEfacePtr = 0 17 it.Context = nil 18 } 19 20 // The current implementation is better in both: 21 // - maintainability 22 // - performance 23 func Benchmark_Performance_Reset(b *testing.B) { 24 b.Run("impl", func(b *testing.B) { 25 b.ReportAllocs() 26 it := NewIterator() 27 b.ResetTimer() 28 for i := 0; i < b.N; i++ { 29 it.reset() 30 } 31 }) 32 b.Run("alter", func(b *testing.B) { 33 b.ReportAllocs() 34 it := NewIterator() 35 b.ResetTimer() 36 for i := 0; i < b.N; i++ { 37 resetTestImpl(it) 38 } 39 }) 40 }