github.com/axiomzen/go-ethereum@v1.8.27/swarm/pot/pot_test.go (about) 1 // Copyright 2017 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 package pot 17 18 import ( 19 "errors" 20 "fmt" 21 "math/rand" 22 "runtime" 23 "sync" 24 "testing" 25 "time" 26 27 "github.com/ethereum/go-ethereum/swarm/log" 28 ) 29 30 const ( 31 maxEachNeighbourTests = 420 32 maxEachNeighbour = 420 33 maxSwap = 420 34 maxSwapTests = 420 35 ) 36 37 // func init() { 38 // log.Root().SetHandler(log.LvlFilterHandler(log.LvlTrace, log.StreamHandler(os.Stderr, log.TerminalFormat(false)))) 39 // } 40 41 type testAddr struct { 42 a []byte 43 i int 44 } 45 46 func newTestAddr(s string, i int) *testAddr { 47 return &testAddr{NewAddressFromString(s), i} 48 } 49 50 func (a *testAddr) Address() []byte { 51 return a.a 52 } 53 54 func (a *testAddr) String() string { 55 return Label(a.a) 56 } 57 58 func randomTestAddr(n int, i int) *testAddr { 59 v := RandomAddress().Bin()[:n] 60 return newTestAddr(v, i) 61 } 62 63 func randomtestAddr(n int, i int) *testAddr { 64 v := RandomAddress().Bin()[:n] 65 return newTestAddr(v, i) 66 } 67 68 func indexes(t *Pot) (i []int) { 69 t.Each(func(v Val) bool { 70 a := v.(*testAddr) 71 i = append(i, a.i) 72 return true 73 }) 74 return i 75 } 76 77 func testAdd(t *Pot, pof Pof, j int, values ...string) (_ *Pot, n int, f bool) { 78 for i, val := range values { 79 t, n, f = Add(t, newTestAddr(val, i+j), pof) 80 } 81 return t, n, f 82 } 83 84 // removing non-existing element from pot 85 func TestPotRemoveNonExisting(t *testing.T) { 86 pof := DefaultPof(8) 87 n := NewPot(newTestAddr("00111100", 0), 0) 88 n, _, _ = Remove(n, newTestAddr("00000101", 0), pof) 89 exp := "00111100" 90 got := Label(n.Pin()) 91 if got[:8] != exp { 92 t.Fatalf("incorrect pinned value. Expected %v, got %v", exp, got[:8]) 93 } 94 } 95 96 // this test creates hierarchical pot tree, and therefore any child node will have 97 // child_po = parent_po + 1. 98 // then removes a node from the middle of the tree. 99 func TestPotRemoveSameBin(t *testing.T) { 100 pof := DefaultPof(8) 101 n := NewPot(newTestAddr("11111111", 0), 0) 102 n, _, _ = testAdd(n, pof, 1, "00000000", "01000000", "01100000", "01110000", "01111000") 103 n, _, _ = Remove(n, newTestAddr("01110000", 0), pof) 104 inds := indexes(n) 105 goti := n.Size() 106 expi := 5 107 if goti != expi { 108 t.Fatalf("incorrect number of elements in Pot. Expected %v, got %v", expi, goti) 109 } 110 inds = indexes(n) 111 got := fmt.Sprintf("%v", inds) 112 exp := "[5 3 2 1 0]" 113 if got != exp { 114 t.Fatalf("incorrect indexes in iteration over Pot. Expected %v, got %v", exp, got) 115 } 116 } 117 118 // this test creates a flat pot tree (all the elements are leafs of one root), 119 // and therefore they all have the same po. 120 // then removes an arbitrary element from the pot. 121 func TestPotRemoveDifferentBins(t *testing.T) { 122 pof := DefaultPof(8) 123 n := NewPot(newTestAddr("11111111", 0), 0) 124 n, _, _ = testAdd(n, pof, 1, "00000000", "10000000", "11000000", "11100000", "11110000") 125 n, _, _ = Remove(n, newTestAddr("11100000", 0), pof) 126 inds := indexes(n) 127 goti := n.Size() 128 expi := 5 129 if goti != expi { 130 t.Fatalf("incorrect number of elements in Pot. Expected %v, got %v", expi, goti) 131 } 132 inds = indexes(n) 133 got := fmt.Sprintf("%v", inds) 134 exp := "[1 2 3 5 0]" 135 if got != exp { 136 t.Fatalf("incorrect indexes in iteration over Pot. Expected %v, got %v", exp, got) 137 } 138 n, _, _ = testAdd(n, pof, 4, "11100000") 139 inds = indexes(n) 140 got = fmt.Sprintf("%v", inds) 141 exp = "[1 2 3 4 5 0]" 142 if got != exp { 143 t.Fatalf("incorrect indexes in iteration over Pot. Expected %v, got %v", exp, got) 144 } 145 } 146 147 func TestPotAdd(t *testing.T) { 148 pof := DefaultPof(8) 149 n := NewPot(newTestAddr("00111100", 0), 0) 150 // Pin set correctly 151 exp := "00111100" 152 got := Label(n.Pin())[:8] 153 if got != exp { 154 t.Fatalf("incorrect pinned value. Expected %v, got %v", exp, got) 155 } 156 // check size 157 goti := n.Size() 158 expi := 1 159 if goti != expi { 160 t.Fatalf("incorrect number of elements in Pot. Expected %v, got %v", expi, goti) 161 } 162 163 n, _, _ = testAdd(n, pof, 1, "01111100", "00111100", "01111100", "00011100") 164 // check size 165 goti = n.Size() 166 expi = 3 167 if goti != expi { 168 t.Fatalf("incorrect number of elements in Pot. Expected %v, got %v", expi, goti) 169 } 170 inds := indexes(n) 171 got = fmt.Sprintf("%v", inds) 172 exp = "[3 4 2]" 173 if got != exp { 174 t.Fatalf("incorrect indexes in iteration over Pot. Expected %v, got %v", exp, got) 175 } 176 } 177 178 func TestPotRemove(t *testing.T) { 179 pof := DefaultPof(8) 180 n := NewPot(newTestAddr("00111100", 0), 0) 181 n, _, _ = Remove(n, newTestAddr("00111100", 0), pof) 182 exp := "<nil>" 183 got := Label(n.Pin()) 184 if got != exp { 185 t.Fatalf("incorrect pinned value. Expected %v, got %v", exp, got) 186 } 187 n, _, _ = testAdd(n, pof, 1, "00000000", "01111100", "00111100", "00011100") 188 n, _, _ = Remove(n, newTestAddr("00111100", 0), pof) 189 goti := n.Size() 190 expi := 3 191 if goti != expi { 192 t.Fatalf("incorrect number of elements in Pot. Expected %v, got %v", expi, goti) 193 } 194 inds := indexes(n) 195 got = fmt.Sprintf("%v", inds) 196 exp = "[2 4 1]" 197 if got != exp { 198 t.Fatalf("incorrect indexes in iteration over Pot. Expected %v, got %v", exp, got) 199 } 200 n, _, _ = Remove(n, newTestAddr("00111100", 0), pof) // remove again same element 201 inds = indexes(n) 202 got = fmt.Sprintf("%v", inds) 203 if got != exp { 204 t.Fatalf("incorrect indexes in iteration over Pot. Expected %v, got %v", exp, got) 205 } 206 n, _, _ = Remove(n, newTestAddr("00000000", 0), pof) // remove the first element 207 inds = indexes(n) 208 got = fmt.Sprintf("%v", inds) 209 exp = "[2 4]" 210 if got != exp { 211 t.Fatalf("incorrect indexes in iteration over Pot. Expected %v, got %v", exp, got) 212 } 213 } 214 215 func TestPotSwap(t *testing.T) { 216 for i := 0; i < maxSwapTests; i++ { 217 alen := maxkeylen 218 pof := DefaultPof(alen) 219 max := rand.Intn(maxSwap) 220 221 n := NewPot(nil, 0) 222 var m []*testAddr 223 var found bool 224 for j := 0; j < 2*max; { 225 v := randomtestAddr(alen, j) 226 n, _, found = Add(n, v, pof) 227 if !found { 228 m = append(m, v) 229 j++ 230 } 231 } 232 k := make(map[string]*testAddr) 233 for j := 0; j < max; { 234 v := randomtestAddr(alen, 1) 235 _, found := k[Label(v)] 236 if !found { 237 k[Label(v)] = v 238 j++ 239 } 240 } 241 for _, v := range k { 242 m = append(m, v) 243 } 244 f := func(v Val) Val { 245 tv := v.(*testAddr) 246 if tv.i < max { 247 return nil 248 } 249 tv.i = 0 250 return v 251 } 252 for _, val := range m { 253 n, _, _, _ = Swap(n, val, pof, func(v Val) Val { 254 if v == nil { 255 return val 256 } 257 return f(v) 258 }) 259 } 260 sum := 0 261 n.Each(func(v Val) bool { 262 if v == nil { 263 return true 264 } 265 sum++ 266 tv := v.(*testAddr) 267 if tv.i > 1 { 268 t.Fatalf("item value incorrect, expected 0, got %v", tv.i) 269 } 270 return true 271 }) 272 if sum != 2*max { 273 t.Fatalf("incorrect number of elements. expected %v, got %v", 2*max, sum) 274 } 275 if sum != n.Size() { 276 t.Fatalf("incorrect size. expected %v, got %v", sum, n.Size()) 277 } 278 } 279 } 280 281 func checkPo(val Val, pof Pof) func(Val, int) error { 282 return func(v Val, po int) error { 283 // check the po 284 exp, _ := pof(val, v, 0) 285 if po != exp { 286 return fmt.Errorf("incorrect prox order for item %v in neighbour iteration for %v. Expected %v, got %v", v, val, exp, po) 287 } 288 return nil 289 } 290 } 291 292 func checkOrder(val Val) func(Val, int) error { 293 po := maxkeylen 294 return func(v Val, p int) error { 295 if po < p { 296 return fmt.Errorf("incorrect order for item %v in neighbour iteration for %v. PO %v > %v (previous max)", v, val, p, po) 297 } 298 po = p 299 return nil 300 } 301 } 302 303 func checkValues(m map[string]bool, val Val) func(Val, int) error { 304 return func(v Val, po int) error { 305 duplicate, ok := m[Label(v)] 306 if !ok { 307 return fmt.Errorf("alien value %v", v) 308 } 309 if duplicate { 310 return fmt.Errorf("duplicate value returned: %v", v) 311 } 312 m[Label(v)] = true 313 return nil 314 } 315 } 316 317 var errNoCount = errors.New("not count") 318 319 func testPotEachNeighbour(n *Pot, pof Pof, val Val, expCount int, fs ...func(Val, int) error) error { 320 var err error 321 var count int 322 n.EachNeighbour(val, pof, func(v Val, po int) bool { 323 for _, f := range fs { 324 err = f(v, po) 325 if err != nil { 326 return err.Error() == errNoCount.Error() 327 } 328 } 329 count++ 330 return count != expCount 331 }) 332 if err == nil && count < expCount { 333 return fmt.Errorf("not enough neighbours returned, expected %v, got %v", expCount, count) 334 } 335 return err 336 } 337 338 const ( 339 mergeTestCount = 5 340 mergeTestChoose = 5 341 ) 342 343 func TestPotMergeCommon(t *testing.T) { 344 vs := make([]*testAddr, mergeTestCount) 345 for i := 0; i < maxEachNeighbourTests; i++ { 346 alen := maxkeylen 347 pof := DefaultPof(alen) 348 349 for j := 0; j < len(vs); j++ { 350 vs[j] = randomtestAddr(alen, j) 351 } 352 max0 := rand.Intn(mergeTestChoose) + 1 353 max1 := rand.Intn(mergeTestChoose) + 1 354 n0 := NewPot(nil, 0) 355 n1 := NewPot(nil, 0) 356 log.Trace(fmt.Sprintf("round %v: %v - %v", i, max0, max1)) 357 m := make(map[string]bool) 358 var found bool 359 for j := 0; j < max0; { 360 r := rand.Intn(max0) 361 v := vs[r] 362 n0, _, found = Add(n0, v, pof) 363 if !found { 364 m[Label(v)] = false 365 j++ 366 } 367 } 368 expAdded := 0 369 370 for j := 0; j < max1; { 371 r := rand.Intn(max1) 372 v := vs[r] 373 n1, _, found = Add(n1, v, pof) 374 if !found { 375 j++ 376 } 377 _, found = m[Label(v)] 378 if !found { 379 expAdded++ 380 m[Label(v)] = false 381 } 382 } 383 if i < 6 { 384 continue 385 } 386 expSize := len(m) 387 log.Trace(fmt.Sprintf("%v-0: pin: %v, size: %v", i, n0.Pin(), max0)) 388 log.Trace(fmt.Sprintf("%v-1: pin: %v, size: %v", i, n1.Pin(), max1)) 389 log.Trace(fmt.Sprintf("%v: merged tree size: %v, newly added: %v", i, expSize, expAdded)) 390 n, common := Union(n0, n1, pof) 391 added := n1.Size() - common 392 size := n.Size() 393 394 if expSize != size { 395 t.Fatalf("%v: incorrect number of elements in merged pot, expected %v, got %v\n%v", i, expSize, size, n) 396 } 397 if expAdded != added { 398 t.Fatalf("%v: incorrect number of added elements in merged pot, expected %v, got %v", i, expAdded, added) 399 } 400 if !checkDuplicates(n) { 401 t.Fatalf("%v: merged pot contains duplicates: \n%v", i, n) 402 } 403 for k := range m { 404 _, _, found = Add(n, newTestAddr(k, 0), pof) 405 if !found { 406 t.Fatalf("%v: merged pot (size:%v, added: %v) missing element %v", i, size, added, k) 407 } 408 } 409 } 410 } 411 412 func TestPotMergeScale(t *testing.T) { 413 for i := 0; i < maxEachNeighbourTests; i++ { 414 alen := maxkeylen 415 pof := DefaultPof(alen) 416 max0 := rand.Intn(maxEachNeighbour) + 1 417 max1 := rand.Intn(maxEachNeighbour) + 1 418 n0 := NewPot(nil, 0) 419 n1 := NewPot(nil, 0) 420 log.Trace(fmt.Sprintf("round %v: %v - %v", i, max0, max1)) 421 m := make(map[string]bool) 422 var found bool 423 for j := 0; j < max0; { 424 v := randomtestAddr(alen, j) 425 n0, _, found = Add(n0, v, pof) 426 if !found { 427 m[Label(v)] = false 428 j++ 429 } 430 } 431 expAdded := 0 432 433 for j := 0; j < max1; { 434 v := randomtestAddr(alen, j) 435 n1, _, found = Add(n1, v, pof) 436 if !found { 437 j++ 438 } 439 _, found = m[Label(v)] 440 if !found { 441 expAdded++ 442 m[Label(v)] = false 443 } 444 } 445 if i < 6 { 446 continue 447 } 448 expSize := len(m) 449 log.Trace(fmt.Sprintf("%v-0: pin: %v, size: %v", i, n0.Pin(), max0)) 450 log.Trace(fmt.Sprintf("%v-1: pin: %v, size: %v", i, n1.Pin(), max1)) 451 log.Trace(fmt.Sprintf("%v: merged tree size: %v, newly added: %v", i, expSize, expAdded)) 452 n, common := Union(n0, n1, pof) 453 added := n1.Size() - common 454 size := n.Size() 455 456 if expSize != size { 457 t.Fatalf("%v: incorrect number of elements in merged pot, expected %v, got %v", i, expSize, size) 458 } 459 if expAdded != added { 460 t.Fatalf("%v: incorrect number of added elements in merged pot, expected %v, got %v", i, expAdded, added) 461 } 462 if !checkDuplicates(n) { 463 t.Fatalf("%v: merged pot contains duplicates", i) 464 } 465 for k := range m { 466 _, _, found = Add(n, newTestAddr(k, 0), pof) 467 if !found { 468 t.Fatalf("%v: merged pot (size:%v, added: %v) missing element %v", i, size, added, k) 469 } 470 } 471 } 472 } 473 474 func checkDuplicates(t *Pot) bool { 475 po := -1 476 for _, c := range t.bins { 477 if c == nil { 478 return false 479 } 480 if c.po <= po || !checkDuplicates(c) { 481 return false 482 } 483 po = c.po 484 } 485 return true 486 } 487 488 func TestPotEachNeighbourSync(t *testing.T) { 489 for i := 0; i < maxEachNeighbourTests; i++ { 490 alen := maxkeylen 491 pof := DefaultPof(maxkeylen) 492 max := rand.Intn(maxEachNeighbour/2) + maxEachNeighbour/2 493 pin := randomTestAddr(alen, 0) 494 n := NewPot(pin, 0) 495 m := make(map[string]bool) 496 m[Label(pin)] = false 497 for j := 1; j <= max; j++ { 498 v := randomTestAddr(alen, j) 499 n, _, _ = Add(n, v, pof) 500 m[Label(v)] = false 501 } 502 503 size := n.Size() 504 if size < 2 { 505 continue 506 } 507 count := rand.Intn(size/2) + size/2 508 val := randomTestAddr(alen, max+1) 509 log.Trace(fmt.Sprintf("%v: pin: %v, size: %v, val: %v, count: %v", i, n.Pin(), size, val, count)) 510 err := testPotEachNeighbour(n, pof, val, count, checkPo(val, pof), checkOrder(val), checkValues(m, val)) 511 if err != nil { 512 t.Fatal(err) 513 } 514 minPoFound := alen 515 maxPoNotFound := 0 516 for k, found := range m { 517 po, _ := pof(val, newTestAddr(k, 0), 0) 518 if found { 519 if po < minPoFound { 520 minPoFound = po 521 } 522 } else { 523 if po > maxPoNotFound { 524 maxPoNotFound = po 525 } 526 } 527 } 528 if minPoFound < maxPoNotFound { 529 t.Fatalf("incorrect neighbours returned: found one with PO %v < there was one not found with PO %v", minPoFound, maxPoNotFound) 530 } 531 } 532 } 533 534 func TestPotEachNeighbourAsync(t *testing.T) { 535 for i := 0; i < maxEachNeighbourTests; i++ { 536 max := rand.Intn(maxEachNeighbour/2) + maxEachNeighbour/2 537 alen := maxkeylen 538 pof := DefaultPof(alen) 539 n := NewPot(randomTestAddr(alen, 0), 0) 540 size := 1 541 var found bool 542 for j := 1; j <= max; j++ { 543 v := randomTestAddr(alen, j) 544 n, _, found = Add(n, v, pof) 545 if !found { 546 size++ 547 } 548 } 549 if size != n.Size() { 550 t.Fatal(n) 551 } 552 if size < 2 { 553 continue 554 } 555 count := rand.Intn(size/2) + size/2 556 val := randomTestAddr(alen, max+1) 557 558 mu := sync.Mutex{} 559 m := make(map[string]bool) 560 maxPos := rand.Intn(alen) 561 log.Trace(fmt.Sprintf("%v: pin: %v, size: %v, val: %v, count: %v, maxPos: %v", i, n.Pin(), size, val, count, maxPos)) 562 msize := 0 563 remember := func(v Val, po int) error { 564 if po > maxPos { 565 return errNoCount 566 } 567 m[Label(v)] = true 568 msize++ 569 return nil 570 } 571 if i == 0 { 572 continue 573 } 574 testPotEachNeighbour(n, pof, val, count, remember) 575 d := 0 576 forget := func(v Val, po int) { 577 mu.Lock() 578 defer mu.Unlock() 579 d++ 580 delete(m, Label(v)) 581 } 582 583 n.EachNeighbourAsync(val, pof, count, maxPos, forget, true) 584 if d != msize { 585 t.Fatalf("incorrect number of neighbour calls in async iterator. expected %v, got %v", msize, d) 586 } 587 if len(m) != 0 { 588 t.Fatalf("incorrect neighbour calls in async iterator. %v items missed:\n%v", len(m), n) 589 } 590 } 591 } 592 593 func benchmarkEachNeighbourSync(t *testing.B, max, count int, d time.Duration) { 594 t.ReportAllocs() 595 alen := maxkeylen 596 pof := DefaultPof(alen) 597 pin := randomTestAddr(alen, 0) 598 n := NewPot(pin, 0) 599 var found bool 600 for j := 1; j <= max; { 601 v := randomTestAddr(alen, j) 602 n, _, found = Add(n, v, pof) 603 if !found { 604 j++ 605 } 606 } 607 t.ResetTimer() 608 for i := 0; i < t.N; i++ { 609 val := randomTestAddr(alen, max+1) 610 m := 0 611 n.EachNeighbour(val, pof, func(v Val, po int) bool { 612 time.Sleep(d) 613 m++ 614 return m != count 615 }) 616 } 617 t.StopTimer() 618 stats := new(runtime.MemStats) 619 runtime.ReadMemStats(stats) 620 } 621 622 func benchmarkEachNeighbourAsync(t *testing.B, max, count int, d time.Duration) { 623 t.ReportAllocs() 624 alen := maxkeylen 625 pof := DefaultPof(alen) 626 pin := randomTestAddr(alen, 0) 627 n := NewPot(pin, 0) 628 var found bool 629 for j := 1; j <= max; { 630 v := randomTestAddr(alen, j) 631 n, _, found = Add(n, v, pof) 632 if !found { 633 j++ 634 } 635 } 636 t.ResetTimer() 637 for i := 0; i < t.N; i++ { 638 val := randomTestAddr(alen, max+1) 639 n.EachNeighbourAsync(val, pof, count, alen, func(v Val, po int) { 640 time.Sleep(d) 641 }, true) 642 } 643 t.StopTimer() 644 stats := new(runtime.MemStats) 645 runtime.ReadMemStats(stats) 646 } 647 648 func BenchmarkEachNeighbourSync_3_1_0(t *testing.B) { 649 benchmarkEachNeighbourSync(t, 1000, 10, 1*time.Microsecond) 650 } 651 func BenchmarkEachNeighboursAsync_3_1_0(t *testing.B) { 652 benchmarkEachNeighbourAsync(t, 1000, 10, 1*time.Microsecond) 653 } 654 func BenchmarkEachNeighbourSync_3_2_0(t *testing.B) { 655 benchmarkEachNeighbourSync(t, 1000, 100, 1*time.Microsecond) 656 } 657 func BenchmarkEachNeighboursAsync_3_2_0(t *testing.B) { 658 benchmarkEachNeighbourAsync(t, 1000, 100, 1*time.Microsecond) 659 } 660 func BenchmarkEachNeighbourSync_3_3_0(t *testing.B) { 661 benchmarkEachNeighbourSync(t, 1000, 1000, 1*time.Microsecond) 662 } 663 func BenchmarkEachNeighboursAsync_3_3_0(t *testing.B) { 664 benchmarkEachNeighbourAsync(t, 1000, 1000, 1*time.Microsecond) 665 } 666 667 func BenchmarkEachNeighbourSync_3_1_1(t *testing.B) { 668 benchmarkEachNeighbourSync(t, 1000, 10, 2*time.Microsecond) 669 } 670 func BenchmarkEachNeighboursAsync_3_1_1(t *testing.B) { 671 benchmarkEachNeighbourAsync(t, 1000, 10, 2*time.Microsecond) 672 } 673 func BenchmarkEachNeighbourSync_3_2_1(t *testing.B) { 674 benchmarkEachNeighbourSync(t, 1000, 100, 2*time.Microsecond) 675 } 676 func BenchmarkEachNeighboursAsync_3_2_1(t *testing.B) { 677 benchmarkEachNeighbourAsync(t, 1000, 100, 2*time.Microsecond) 678 } 679 func BenchmarkEachNeighbourSync_3_3_1(t *testing.B) { 680 benchmarkEachNeighbourSync(t, 1000, 1000, 2*time.Microsecond) 681 } 682 func BenchmarkEachNeighboursAsync_3_3_1(t *testing.B) { 683 benchmarkEachNeighbourAsync(t, 1000, 1000, 2*time.Microsecond) 684 } 685 686 func BenchmarkEachNeighbourSync_3_1_2(t *testing.B) { 687 benchmarkEachNeighbourSync(t, 1000, 10, 4*time.Microsecond) 688 } 689 func BenchmarkEachNeighboursAsync_3_1_2(t *testing.B) { 690 benchmarkEachNeighbourAsync(t, 1000, 10, 4*time.Microsecond) 691 } 692 func BenchmarkEachNeighbourSync_3_2_2(t *testing.B) { 693 benchmarkEachNeighbourSync(t, 1000, 100, 4*time.Microsecond) 694 } 695 func BenchmarkEachNeighboursAsync_3_2_2(t *testing.B) { 696 benchmarkEachNeighbourAsync(t, 1000, 100, 4*time.Microsecond) 697 } 698 func BenchmarkEachNeighbourSync_3_3_2(t *testing.B) { 699 benchmarkEachNeighbourSync(t, 1000, 1000, 4*time.Microsecond) 700 } 701 func BenchmarkEachNeighboursAsync_3_3_2(t *testing.B) { 702 benchmarkEachNeighbourAsync(t, 1000, 1000, 4*time.Microsecond) 703 } 704 705 func BenchmarkEachNeighbourSync_3_1_3(t *testing.B) { 706 benchmarkEachNeighbourSync(t, 1000, 10, 8*time.Microsecond) 707 } 708 func BenchmarkEachNeighboursAsync_3_1_3(t *testing.B) { 709 benchmarkEachNeighbourAsync(t, 1000, 10, 8*time.Microsecond) 710 } 711 func BenchmarkEachNeighbourSync_3_2_3(t *testing.B) { 712 benchmarkEachNeighbourSync(t, 1000, 100, 8*time.Microsecond) 713 } 714 func BenchmarkEachNeighboursAsync_3_2_3(t *testing.B) { 715 benchmarkEachNeighbourAsync(t, 1000, 100, 8*time.Microsecond) 716 } 717 func BenchmarkEachNeighbourSync_3_3_3(t *testing.B) { 718 benchmarkEachNeighbourSync(t, 1000, 1000, 8*time.Microsecond) 719 } 720 func BenchmarkEachNeighboursAsync_3_3_3(t *testing.B) { 721 benchmarkEachNeighbourAsync(t, 1000, 1000, 8*time.Microsecond) 722 } 723 724 func BenchmarkEachNeighbourSync_3_1_4(t *testing.B) { 725 benchmarkEachNeighbourSync(t, 1000, 10, 16*time.Microsecond) 726 } 727 func BenchmarkEachNeighboursAsync_3_1_4(t *testing.B) { 728 benchmarkEachNeighbourAsync(t, 1000, 10, 16*time.Microsecond) 729 } 730 func BenchmarkEachNeighbourSync_3_2_4(t *testing.B) { 731 benchmarkEachNeighbourSync(t, 1000, 100, 16*time.Microsecond) 732 } 733 func BenchmarkEachNeighboursAsync_3_2_4(t *testing.B) { 734 benchmarkEachNeighbourAsync(t, 1000, 100, 16*time.Microsecond) 735 } 736 func BenchmarkEachNeighbourSync_3_3_4(t *testing.B) { 737 benchmarkEachNeighbourSync(t, 1000, 1000, 16*time.Microsecond) 738 } 739 func BenchmarkEachNeighboursAsync_3_3_4(t *testing.B) { 740 benchmarkEachNeighbourAsync(t, 1000, 1000, 16*time.Microsecond) 741 }