SHARE
TWEET

Untitled

a guest Jul 21st, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package structescape
  2.  
  3. import "testing"
  4.  
  5. type DataContainer struct {
  6.     a []byte
  7. }
  8.  
  9. var d *DataContainer
  10.  
  11. func Benchmark_Inline_Heap(b *testing.B) {
  12.     for i := 0; i < b.N; i++ {
  13.         // heap
  14.         d = &DataContainer{
  15.             //heap
  16.             a: make([]byte, 1024),
  17.         }
  18.         _ = d
  19.     }
  20. }
  21.  
  22. func Benchmark_NotInline_Heap(b *testing.B) {
  23.     for i := 0; i < b.N; i++ {
  24.         // heap
  25.         d = &DataContainer{}
  26.         // heap
  27.         d.a = make([]byte, 1024)
  28.         _ = d
  29.     }
  30. }
  31.  
  32. func Benchmark_Inline_Stack(b *testing.B) {
  33.     for i := 0; i < b.N; i++ {
  34.         // stack
  35.         d := &DataContainer{
  36.             // stack
  37.             make([]byte, 1024),
  38.         }
  39.         _ = d
  40.     }
  41. }
  42.  
  43. func Benchmark_NotInline(b *testing.B) {
  44.     for i := 0; i < b.N; i++ {
  45.         // d is in stack
  46.         d := &DataContainer{}
  47.         // d.a is in heap
  48.         d.a = make([]byte, 1024)
  49.         _ = d
  50.     }
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top