github.com/egonelbre/exp@v0.0.0-20240430123955-ed1d3aa93911/bench/vector/vector32_test.go (about)

     1  package vector_test
     2  
     3  import (
     4  	"runtime"
     5  	"testing"
     6  )
     7  
     8  var V32s1 = V32s3{1, 1, 1}
     9  
    10  type V32s3 struct{ X, Y, Z float32 }
    11  
    12  func (a *V32s3) PP_Add(b *V32s3)         { a.X += b.X; a.Y += b.Y; a.Z += b.Z }
    13  func (a *V32s3) PN_Add(b V32s3)          { a.X += b.X; a.Y += b.Y; a.Z += b.Z }
    14  func (a *V32s3) PPP_Add(b *V32s3) *V32s3 { return &V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    15  func (a V32s3) NNN_Add(b V32s3) V32s3    { return V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    16  func (a *V32s3) PPN_Add(b *V32s3) V32s3  { return V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    17  func (a *V32s3) PNP_Add(b V32s3) *V32s3  { return &V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    18  func (a V32s3) NPP_Add(b *V32s3) *V32s3  { return &V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    19  func (a V32s3) NNP_Add(b V32s3) *V32s3   { return &V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    20  func (a V32s3) NPN_Add(b *V32s3) V32s3   { return V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    21  func (a *V32s3) PNN_Add(b V32s3) V32s3   { return V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    22  
    23  func (a *V32s3) PPZ_Add(b *V32s3, r *V32s3) { *r = V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    24  func (a V32s3) NPZ_Add(b *V32s3, r *V32s3)  { *r = V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    25  func (a *V32s3) PNZ_Add(b V32s3, r *V32s3)  { *r = V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    26  func (a V32s3) NNZ_Add(b V32s3, r *V32s3)   { *r = V32s3{a.X + b.X, a.Y + b.Y, a.Z + b.Z} }
    27  
    28  func (a *V32s3) PPY_Add(b *V32s3, r *V32s3) { r.X = a.X + b.X; r.Y = a.Y + b.Y; r.Z = a.Z + b.Z }
    29  func (a V32s3) NPY_Add(b *V32s3, r *V32s3)  { r.X = a.X + b.X; r.Y = a.Y + b.Y; r.Z = a.Z + b.Z }
    30  func (a *V32s3) PNY_Add(b V32s3, r *V32s3)  { r.X = a.X + b.X; r.Y = a.Y + b.Y; r.Z = a.Z + b.Z }
    31  func (a V32s3) NNY_Add(b V32s3, r *V32s3)   { r.X = a.X + b.X; r.Y = a.Y + b.Y; r.Z = a.Z + b.Z }
    32  
    33  func BenchmarkAdd_PP_V32s3(t *testing.B) {
    34  	a, b := V32s1, V32s1
    35  	for i := 0; i < t.N; i++ {
    36  		a.PP_Add(&b)
    37  	}
    38  	runtime.KeepAlive(a)
    39  	runtime.KeepAlive(b)
    40  }
    41  func BenchmarkAdd_PN_V32s3(t *testing.B) {
    42  	a, b := V32s1, V32s1
    43  	for i := 0; i < t.N; i++ {
    44  		a.PN_Add(b)
    45  	}
    46  	runtime.KeepAlive(a)
    47  	runtime.KeepAlive(b)
    48  }
    49  func BenchmarkAdd_PPP_V32s3(t *testing.B) {
    50  	a, b := V32s1, V32s1
    51  	for i := 0; i < t.N; i++ {
    52  		a = *a.PPP_Add(&b)
    53  	}
    54  	runtime.KeepAlive(a)
    55  	runtime.KeepAlive(b)
    56  }
    57  func BenchmarkAdd_NNN_V32s3(t *testing.B) {
    58  	a, b := V32s1, V32s1
    59  	for i := 0; i < t.N; i++ {
    60  		a = a.NNN_Add(b)
    61  	}
    62  	runtime.KeepAlive(a)
    63  	runtime.KeepAlive(b)
    64  }
    65  func BenchmarkAdd_PPN_V32s3(t *testing.B) {
    66  	a, b := V32s1, V32s1
    67  	for i := 0; i < t.N; i++ {
    68  		a = a.PPN_Add(&b)
    69  	}
    70  	runtime.KeepAlive(a)
    71  	runtime.KeepAlive(b)
    72  }
    73  func BenchmarkAdd_PNP_V32s3(t *testing.B) {
    74  	a, b := V32s1, V32s1
    75  	for i := 0; i < t.N; i++ {
    76  		a = *a.PNP_Add(b)
    77  	}
    78  	runtime.KeepAlive(a)
    79  	runtime.KeepAlive(b)
    80  }
    81  func BenchmarkAdd_NPP_V32s3(t *testing.B) {
    82  	a, b := V32s1, V32s1
    83  	for i := 0; i < t.N; i++ {
    84  		a = *a.NPP_Add(&b)
    85  	}
    86  	runtime.KeepAlive(a)
    87  	runtime.KeepAlive(b)
    88  }
    89  func BenchmarkAdd_NNP_V32s3(t *testing.B) {
    90  	a, b := V32s1, V32s1
    91  	for i := 0; i < t.N; i++ {
    92  		a = *a.NNP_Add(b)
    93  	}
    94  	runtime.KeepAlive(a)
    95  	runtime.KeepAlive(b)
    96  }
    97  func BenchmarkAdd_NPN_V32s3(t *testing.B) {
    98  	a, b := V32s1, V32s1
    99  	for i := 0; i < t.N; i++ {
   100  		a = a.NPN_Add(&b)
   101  	}
   102  	runtime.KeepAlive(a)
   103  	runtime.KeepAlive(b)
   104  }
   105  func BenchmarkAdd_PNN_V32s3(t *testing.B) {
   106  	a, b := V32s1, V32s1
   107  	for i := 0; i < t.N; i++ {
   108  		a = a.PNN_Add(b)
   109  	}
   110  	runtime.KeepAlive(a)
   111  	runtime.KeepAlive(b)
   112  }
   113  
   114  func BenchmarkAdd_PPZ_V32s3(t *testing.B) {
   115  	a, b := V32s1, V32s1
   116  	for i := 0; i < t.N; i++ {
   117  		a.PPZ_Add(&b, &a)
   118  	}
   119  	runtime.KeepAlive(a)
   120  	runtime.KeepAlive(b)
   121  }
   122  func BenchmarkAdd_NPZ_V32s3(t *testing.B) {
   123  	a, b := V32s1, V32s1
   124  	for i := 0; i < t.N; i++ {
   125  		a.NPZ_Add(&b, &a)
   126  	}
   127  	runtime.KeepAlive(a)
   128  	runtime.KeepAlive(b)
   129  }
   130  func BenchmarkAdd_PNZ_V32s3(t *testing.B) {
   131  	a, b := V32s1, V32s1
   132  	for i := 0; i < t.N; i++ {
   133  		a.PNZ_Add(b, &a)
   134  	}
   135  	runtime.KeepAlive(a)
   136  	runtime.KeepAlive(b)
   137  }
   138  func BenchmarkAdd_NNZ_V32s3(t *testing.B) {
   139  	a, b := V32s1, V32s1
   140  	for i := 0; i < t.N; i++ {
   141  		a.NNZ_Add(b, &a)
   142  	}
   143  	runtime.KeepAlive(a)
   144  	runtime.KeepAlive(b)
   145  }
   146  
   147  func BenchmarkAdd_PPY_V32s3(t *testing.B) {
   148  	a, b := V32s1, V32s1
   149  	for i := 0; i < t.N; i++ {
   150  		a.PPY_Add(&b, &a)
   151  	}
   152  	runtime.KeepAlive(a)
   153  	runtime.KeepAlive(b)
   154  }
   155  func BenchmarkAdd_NPY_V32s3(t *testing.B) {
   156  	a, b := V32s1, V32s1
   157  	for i := 0; i < t.N; i++ {
   158  		a.NPY_Add(&b, &a)
   159  	}
   160  	runtime.KeepAlive(a)
   161  	runtime.KeepAlive(b)
   162  }
   163  func BenchmarkAdd_PNY_V32s3(t *testing.B) {
   164  	a, b := V32s1, V32s1
   165  	for i := 0; i < t.N; i++ {
   166  		a.PNY_Add(b, &a)
   167  	}
   168  	runtime.KeepAlive(a)
   169  	runtime.KeepAlive(b)
   170  }
   171  func BenchmarkAdd_NNY_V32s3(t *testing.B) {
   172  	a, b := V32s1, V32s1
   173  	for i := 0; i < t.N; i++ {
   174  		a.NNY_Add(b, &a)
   175  	}
   176  	runtime.KeepAlive(a)
   177  	runtime.KeepAlive(b)
   178  }
   179  
   180  var V32a1 = V32a3{1, 1, 1}
   181  
   182  type V32a3 [3]float32
   183  
   184  func (a *V32a3) PP_Add(b *V32a3)         { a[0] += b[0]; a[1] += b[1]; a[2] += b[2] }
   185  func (a *V32a3) PN_Add(b V32a3)          { a[0] += b[0]; a[1] += b[1]; a[2] += b[2] }
   186  func (a *V32a3) PPP_Add(b *V32a3) *V32a3 { return &V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   187  func (a V32a3) NNN_Add(b V32a3) V32a3    { return V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   188  func (a *V32a3) PPN_Add(b *V32a3) V32a3  { return V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   189  func (a *V32a3) PNP_Add(b V32a3) *V32a3  { return &V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   190  func (a V32a3) NPP_Add(b *V32a3) *V32a3  { return &V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   191  func (a V32a3) NNP_Add(b V32a3) *V32a3   { return &V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   192  func (a V32a3) NPN_Add(b *V32a3) V32a3   { return V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   193  func (a *V32a3) PNN_Add(b V32a3) V32a3   { return V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   194  
   195  func (a *V32a3) PPZ_Add(b *V32a3, r *V32a3) { *r = V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   196  func (a V32a3) NPZ_Add(b *V32a3, r *V32a3)  { *r = V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   197  func (a *V32a3) PNZ_Add(b V32a3, r *V32a3)  { *r = V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   198  func (a V32a3) NNZ_Add(b V32a3, r *V32a3)   { *r = V32a3{a[0] + b[0], a[1] + b[1], a[2] + b[2]} }
   199  
   200  func (a *V32a3) PPY_Add(b *V32a3, r *V32a3) {
   201  	r[0] = a[0] + b[0]
   202  	r[1] = a[1] + b[1]
   203  	r[2] = a[2] + b[2]
   204  }
   205  func (a V32a3) NPY_Add(b *V32a3, r *V32a3) { r[0] = a[0] + b[0]; r[1] = a[1] + b[1]; r[2] = a[2] + b[2] }
   206  func (a *V32a3) PNY_Add(b V32a3, r *V32a3) { r[0] = a[0] + b[0]; r[1] = a[1] + b[1]; r[2] = a[2] + b[2] }
   207  func (a V32a3) NNY_Add(b V32a3, r *V32a3)  { r[0] = a[0] + b[0]; r[1] = a[1] + b[1]; r[2] = a[2] + b[2] }
   208  
   209  func BenchmarkAdd_PP_V32a3(t *testing.B) {
   210  	a, b := V32a1, V32a1
   211  	for i := 0; i < t.N; i++ {
   212  		a.PP_Add(&b)
   213  	}
   214  	runtime.KeepAlive(a)
   215  	runtime.KeepAlive(b)
   216  }
   217  func BenchmarkAdd_PN_V32a3(t *testing.B) {
   218  	a, b := V32a1, V32a1
   219  	for i := 0; i < t.N; i++ {
   220  		a.PN_Add(b)
   221  	}
   222  	runtime.KeepAlive(a)
   223  	runtime.KeepAlive(b)
   224  }
   225  func BenchmarkAdd_PPP_V32a3(t *testing.B) {
   226  	a, b := V32a1, V32a1
   227  	for i := 0; i < t.N; i++ {
   228  		a = *a.PPP_Add(&b)
   229  	}
   230  	runtime.KeepAlive(a)
   231  	runtime.KeepAlive(b)
   232  }
   233  func BenchmarkAdd_NNN_V32a3(t *testing.B) {
   234  	a, b := V32a1, V32a1
   235  	for i := 0; i < t.N; i++ {
   236  		a = a.NNN_Add(b)
   237  	}
   238  	runtime.KeepAlive(a)
   239  	runtime.KeepAlive(b)
   240  }
   241  func BenchmarkAdd_PPN_V32a3(t *testing.B) {
   242  	a, b := V32a1, V32a1
   243  	for i := 0; i < t.N; i++ {
   244  		a = a.PPN_Add(&b)
   245  	}
   246  	runtime.KeepAlive(a)
   247  	runtime.KeepAlive(b)
   248  }
   249  func BenchmarkAdd_PNP_V32a3(t *testing.B) {
   250  	a, b := V32a1, V32a1
   251  	for i := 0; i < t.N; i++ {
   252  		a = *a.PNP_Add(b)
   253  	}
   254  	runtime.KeepAlive(a)
   255  	runtime.KeepAlive(b)
   256  }
   257  func BenchmarkAdd_NPP_V32a3(t *testing.B) {
   258  	a, b := V32a1, V32a1
   259  	for i := 0; i < t.N; i++ {
   260  		a = *a.NPP_Add(&b)
   261  	}
   262  	runtime.KeepAlive(a)
   263  	runtime.KeepAlive(b)
   264  }
   265  func BenchmarkAdd_NNP_V32a3(t *testing.B) {
   266  	a, b := V32a1, V32a1
   267  	for i := 0; i < t.N; i++ {
   268  		a = *a.NNP_Add(b)
   269  	}
   270  	runtime.KeepAlive(a)
   271  	runtime.KeepAlive(b)
   272  }
   273  func BenchmarkAdd_NPN_V32a3(t *testing.B) {
   274  	a, b := V32a1, V32a1
   275  	for i := 0; i < t.N; i++ {
   276  		a = a.NPN_Add(&b)
   277  	}
   278  	runtime.KeepAlive(a)
   279  	runtime.KeepAlive(b)
   280  }
   281  func BenchmarkAdd_PNN_V32a3(t *testing.B) {
   282  	a, b := V32a1, V32a1
   283  	for i := 0; i < t.N; i++ {
   284  		a = a.PNN_Add(b)
   285  	}
   286  	runtime.KeepAlive(a)
   287  	runtime.KeepAlive(b)
   288  }
   289  
   290  func BenchmarkAdd_PPZ_V32a3(t *testing.B) {
   291  	a, b := V32a1, V32a1
   292  	for i := 0; i < t.N; i++ {
   293  		a.PPZ_Add(&b, &a)
   294  	}
   295  	runtime.KeepAlive(a)
   296  	runtime.KeepAlive(b)
   297  }
   298  func BenchmarkAdd_NPZ_V32a3(t *testing.B) {
   299  	a, b := V32a1, V32a1
   300  	for i := 0; i < t.N; i++ {
   301  		a.NPZ_Add(&b, &a)
   302  	}
   303  	runtime.KeepAlive(a)
   304  	runtime.KeepAlive(b)
   305  }
   306  func BenchmarkAdd_PNZ_V32a3(t *testing.B) {
   307  	a, b := V32a1, V32a1
   308  	for i := 0; i < t.N; i++ {
   309  		a.PNZ_Add(b, &a)
   310  	}
   311  	runtime.KeepAlive(a)
   312  	runtime.KeepAlive(b)
   313  }
   314  func BenchmarkAdd_NNZ_V32a3(t *testing.B) {
   315  	a, b := V32a1, V32a1
   316  	for i := 0; i < t.N; i++ {
   317  		a.NNZ_Add(b, &a)
   318  	}
   319  	runtime.KeepAlive(a)
   320  	runtime.KeepAlive(b)
   321  }
   322  
   323  func BenchmarkAdd_PPY_V32a3(t *testing.B) {
   324  	a, b := V32a1, V32a1
   325  	for i := 0; i < t.N; i++ {
   326  		a.PPY_Add(&b, &a)
   327  	}
   328  	runtime.KeepAlive(a)
   329  	runtime.KeepAlive(b)
   330  }
   331  func BenchmarkAdd_NPY_V32a3(t *testing.B) {
   332  	a, b := V32a1, V32a1
   333  	for i := 0; i < t.N; i++ {
   334  		a.NPY_Add(&b, &a)
   335  	}
   336  	runtime.KeepAlive(a)
   337  	runtime.KeepAlive(b)
   338  }
   339  func BenchmarkAdd_PNY_V32a3(t *testing.B) {
   340  	a, b := V32a1, V32a1
   341  	for i := 0; i < t.N; i++ {
   342  		a.PNY_Add(b, &a)
   343  	}
   344  	runtime.KeepAlive(a)
   345  	runtime.KeepAlive(b)
   346  }
   347  func BenchmarkAdd_NNY_V32a3(t *testing.B) {
   348  	a, b := V32a1, V32a1
   349  	for i := 0; i < t.N; i++ {
   350  		a.NNY_Add(b, &a)
   351  	}
   352  	runtime.KeepAlive(a)
   353  	runtime.KeepAlive(b)
   354  }