Advertisement
Guest User

Untitled

a guest
Oct 27th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.33 KB | None | 0 0
  1. BenchmarkTemplateParallel 200000000 18.1 ns/op 0 B/op 0 allocs/op
  2. BenchmarkTemplateParallel-6 100000000 41.0 ns/op 0 B/op 0 allocs/op
  3. BenchmarkTemplateParallel-12 200000000 25.9 ns/op 0 B/op 0 allocs/op
  4. BenchmarkTemplateParallel2 200000000 20.7 ns/op 0 B/op 0 allocs/op
  5. BenchmarkTemplateParallel2-6 100000000 37.3 ns/op 0 B/op 0 allocs/op
  6. BenchmarkTemplateParallel2-12 100000000 30.1 ns/op 0 B/op 0 allocs/op
  7. BenchmarkTemplateParallel3 200000000 19.9 ns/op 0 B/op 0 allocs/op
  8. BenchmarkTemplateParallel3-6 100000000 32.2 ns/op 0 B/op 0 allocs/op
  9. BenchmarkTemplateParallel3-12 200000000 28.8 ns/op 0 B/op 0 allocs/op
  10.  
  11.  
  12.  
  13. package main
  14.  
  15. import (
  16. // "flag"
  17. // "runtime"
  18. // "fmt"
  19. "sync/atomic"
  20. "testing"
  21. // "time"
  22. // "github.com/OneOfOne/lfchan/typed/uint64Chan"
  23. )
  24.  
  25. // func TestAr(t *testing.T) {
  26.  
  27. // ar := make([]int32, 16)
  28.  
  29. // for i := 0; i < 50; i++ {
  30. // //p := i & ((2 ^ 5) - 1)
  31. // p := i % 16
  32. // fmt.Println(i, p)
  33. // // ar[p] = ar[p] + 1
  34. // }
  35.  
  36. // fmt.Println(ar)
  37.  
  38. // // ch := New()
  39. // // var want, got int
  40. // // for i := 0; i < 100; i++ {
  41. // // go ch.Send(i, true)
  42. // // want += i
  43. // // }
  44. // // for i := 0; i < 100; i++ {
  45. // // v, ok := ch.Recv(true)
  46. // // if !ok {
  47. // // t.Fatal("!ok")
  48. // // }
  49. // // got += v.(int)
  50. // // }
  51. // // if want != got {
  52. // // t.Fatalf("wanted %v, got %v", want, got)
  53. // // }
  54. // }
  55.  
  56. type Block struct {
  57. p int32
  58. // _padding3 [8]uint64
  59. }
  60.  
  61. func BenchmarkTemplateParallel(b *testing.B) {
  62. // templ := template.Must(template.New("test").Parse("Hello, {{.}}!"))
  63. var pos int32 = 0
  64. ar := make([]Block, 16)
  65.  
  66. for i := 0; i < 16; i++ {
  67. ar[i] = Block{0}
  68. }
  69.  
  70. b.RunParallel(func(pb *testing.PB) {
  71. // var buf bytes.Buffer
  72. for pb.Next() {
  73. p := atomic.AddInt32(&pos, 1)
  74. p = p % 16
  75. atomic.AddInt32(&ar[p].p, 1)
  76.  
  77. }
  78. })
  79.  
  80. // fmt.Println(ar)
  81. }
  82.  
  83. type Block2 struct {
  84. p int32
  85. _padding [8]uint64
  86. }
  87.  
  88. func BenchmarkTemplateParallel2(b *testing.B) {
  89. // templ := template.Must(template.New("test").Parse("Hello, {{.}}!"))
  90. var pos int32 = 0
  91. ar := make([]Block2, 16)
  92.  
  93. for i := 0; i < 16; i++ {
  94. ar[i] = Block2{p: 0}
  95. }
  96.  
  97. b.RunParallel(func(pb *testing.PB) {
  98. // var buf bytes.Buffer
  99. for pb.Next() {
  100. p := atomic.AddInt32(&pos, 1)
  101. p = p % 16
  102. atomic.AddInt32(&ar[p].p, 1)
  103.  
  104. }
  105. })
  106.  
  107. // fmt.Println(ar)
  108. }
  109.  
  110.  
  111. type Block3 struct {
  112. p int64
  113. _padding [64]uint64
  114. }
  115.  
  116. func BenchmarkTemplateParallel3(b *testing.B) {
  117. // templ := template.Must(template.New("test").Parse("Hello, {{.}}!"))
  118. var pos int64 = 0
  119. ar := make([]Block3, 16)
  120.  
  121. for i := 0; i < 16; i++ {
  122. ar[i] = Block3{p: 0}
  123. }
  124.  
  125. b.RunParallel(func(pb *testing.PB) {
  126. // var buf bytes.Buffer
  127. for pb.Next() {
  128. p := atomic.AddInt64(&pos, 1)
  129. p = p % 16
  130. atomic.AddInt64(&ar[p].p, 1)
  131.  
  132. }
  133. })
  134.  
  135. // fmt.Println(ar)
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement