github.com/qioalice/ekago/v3@v3.3.2-0.20221202205325-5c262d586ee4/ekasys/stackframe_bench_test.go (about) 1 // Copyright © 2021. All rights reserved. 2 // Author: Ilya Stroy. 3 // Contacts: iyuryevich@pm.me, https://github.com/qioalice 4 // License: https://opensource.org/licenses/MIT 5 6 package ekasys 7 8 import ( 9 "testing" 10 ) 11 12 // benchGetStackFramePointsCommonDepth aux bench func that starts 13 // getStackFramePoints bench with specified 'depth' arg. 14 func benchGetStackFramePointsCommonDepth(b *testing.B, depth int) { 15 16 b.ReportAllocs() 17 b.ResetTimer() 18 19 for i := 0; i < b.N; i++ { 20 _ = getStackFramePoints(0, depth) 21 } 22 } 23 24 // benchGetStackFramePointsSyntheticDepth increases stack depth level artificially 25 // by 'createDepth' value and then starts getStackFramePoints bench with 26 // specified 'depth' arg. 27 func benchGetStackFramePointsSyntheticDepth(b *testing.B, depth, createDepth int) { 28 29 type tF func(int, int) []uintptr 30 31 wrapper := func(f tF) tF { 32 return func(i1 int, i2 int) []uintptr { 33 return f(i1, i2) 34 } 35 } 36 37 var f tF = getStackFramePoints 38 39 for i := 0; i < createDepth; i++ { 40 f = wrapper(f) 41 } 42 43 b.ReportAllocs() 44 b.ResetTimer() 45 46 for i := 0; i < b.N; i++ { 47 _ = f(0, depth) 48 } 49 } 50 51 // Bench getStackFramePoints with 'skip' == 0, 'depth' == 1 on common stack. 52 func Benchmark_getStackFramePoints_CommonDepth_1(b *testing.B) { 53 benchGetStackFramePointsCommonDepth(b, 1) 54 } 55 56 // Bench getStackFramePoints with 'skip' == 0, 'depth' == 10 on common stack. 57 func Benchmark_getStackFramePoints_CommonDepth_10(b *testing.B) { 58 benchGetStackFramePointsCommonDepth(b, 10) 59 } 60 61 // Bench getStackFramePoints with 'skip' == 0, 'depth' == -1 (full depth) 62 // on common stack. 63 func Benchmark_getStackFramePoints_CommonDepth_Full(b *testing.B) { 64 benchGetStackFramePointsCommonDepth(b, -1) 65 } 66 67 // Bench getStackFramePoints with 'skip' == 0, 'depth' == 1 68 // on artificially enlarged stack by 10. 69 func Benchmark_getStackFramePoints_SyntheticDepth_1_of_10(b *testing.B) { 70 benchGetStackFramePointsSyntheticDepth(b, 1, 10) 71 } 72 73 // Bench getStackFramePoints with 'skip' == 0, 'depth' == 10 74 // on artificially enlarged stack by 10. 75 func Benchmark_getStackFramePoints_SyntheticDepth_10_of_10(b *testing.B) { 76 benchGetStackFramePointsSyntheticDepth(b, 10, 10) 77 } 78 79 // Bench getStackFramePoints with 'skip' == 0, 'depth' == -1 (full depth) 80 // on artificially enlarged stack by 10. 81 func Benchmark_getStackFramePoints_SyntheticDepth_Full_of_10(b *testing.B) { 82 benchGetStackFramePointsSyntheticDepth(b, -1, 10) 83 } 84 85 // Bench getStackFramePoints with 'skip' == 0, 'depth' == 10 86 // on artificially enlarged stack by 10. 87 func Benchmark_getStackFramePoints_SyntheticDepth_10_of_20(b *testing.B) { 88 benchGetStackFramePointsSyntheticDepth(b, 10, 20) 89 } 90 91 // Bench getStackFramePoints with 'skip' == 0, 'depth' == -1 (full depth) 92 // on artificially enlarged stack by 10. 93 func Benchmark_getStackFramePoints_SyntheticDepth_Full_of_20(b *testing.B) { 94 benchGetStackFramePointsSyntheticDepth(b, -1, 20) 95 }