(t *testing.T)
| 86 | } |
| 87 | |
| 88 | func TestXidmapMemory(t *testing.T) { |
| 89 | var loop uint32 |
| 90 | bToMb := func(b uint64) uint64 { |
| 91 | return b / 1024 / 1024 |
| 92 | } |
| 93 | printMemory := func() { |
| 94 | var m runtime.MemStats |
| 95 | runtime.ReadMemStats(&m) |
| 96 | // For info on each, see: https://golang.org/pkg/runtime/#MemStats |
| 97 | fmt.Printf(" Heap = %v M", bToMb(m.HeapInuse)) |
| 98 | fmt.Printf(" Alloc = %v M", bToMb(m.Alloc)) |
| 99 | fmt.Printf(" Sys = %v M", bToMb(m.Sys)) |
| 100 | fmt.Printf(" Loop = %.2fM", float64(atomic.LoadUint32(&loop))/1e6) |
| 101 | fmt.Printf(" NumGC = %v\n", m.NumGC) |
| 102 | } |
| 103 | ticker := time.Tick(time.Second) |
| 104 | |
| 105 | go func() { |
| 106 | for range ticker { |
| 107 | printMemory() |
| 108 | } |
| 109 | }() |
| 110 | |
| 111 | conn, err := x.SetupConnection(testutil.GetSockAddrZero(), nil, false) |
| 112 | require.NoError(t, err) |
| 113 | require.NotNil(t, conn) |
| 114 | |
| 115 | xidmap := New(getTestXidmapOpts(conn, nil)) |
| 116 | defer xidmap.Flush() |
| 117 | |
| 118 | start := time.Now() |
| 119 | var wg sync.WaitGroup |
| 120 | for numGo := 0; numGo < 32; numGo++ { |
| 121 | wg.Add(1) |
| 122 | go func() { |
| 123 | defer wg.Done() |
| 124 | for { |
| 125 | i := atomic.AddUint32(&loop, 1) |
| 126 | if i > 10e6 { |
| 127 | return |
| 128 | } |
| 129 | xidmap.AssignUid(fmt.Sprintf("xid-%d", i)) |
| 130 | } |
| 131 | }() |
| 132 | } |
| 133 | wg.Wait() |
| 134 | t.Logf("Time taken: %v", time.Since(start).Round(time.Millisecond)) |
| 135 | } |
| 136 | |
| 137 | // Benchmarks using Map |
| 138 | // BenchmarkXidmapWrites-32 4435590 278 ns/op |
nothing calls this directly
no test coverage detected