(testingB *testing.B, nLines, nCursors int)
| 150 | } |
| 151 | |
| 152 | func benchEdit(testingB *testing.B, nLines, nCursors int) { |
| 153 | rand.Seed(int64(nLines + nCursors)) |
| 154 | |
| 155 | b := NewBufferFromString(randomText(nLines), "", BTDefault) |
| 156 | |
| 157 | regionSize := nLines / nCursors |
| 158 | |
| 159 | operations := make([]operation, nCursors) |
| 160 | for i := range operations { |
| 161 | startLine := (i * regionSize) + rand.Intn(regionSize-5) |
| 162 | startColumn := rand.Intn(util.CharacterCountInString(b.Line(startLine)) + 1) |
| 163 | endLine := startLine + 1 + rand.Intn(5) |
| 164 | endColumn := rand.Intn(util.CharacterCountInString(b.Line(endLine)) + 1) |
| 165 | |
| 166 | operations[i] = operation{ |
| 167 | start: Loc{startColumn, startLine}, |
| 168 | end: Loc{endColumn, endLine}, |
| 169 | text: []string{randomText(2 + rand.Intn(4))}, |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | testingB.ResetTimer() |
| 174 | |
| 175 | for i := 0; i < testingB.N; i++ { |
| 176 | b.SetCursors([]*Cursor{}) |
| 177 | |
| 178 | var cursors []*Cursor |
| 179 | |
| 180 | for _, op := range operations { |
| 181 | cursor := NewCursor(b, op.start) |
| 182 | cursor.SetSelectionStart(op.start) |
| 183 | cursor.SetSelectionEnd(op.end) |
| 184 | b.AddCursor(cursor) |
| 185 | cursors = append(cursors, cursor) |
| 186 | } |
| 187 | |
| 188 | for j, op := range operations { |
| 189 | cursor := cursors[j] |
| 190 | b.SetCurCursor(cursor.Num) |
| 191 | cursor.DeleteSelection() |
| 192 | b.Insert(cursor.Loc, op.text[0]) |
| 193 | } |
| 194 | |
| 195 | for b.UndoStack.Peek() != nil { |
| 196 | b.UndoOneEvent() |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | testingB.StopTimer() |
| 201 | |
| 202 | b.Close() |
| 203 | } |
| 204 | |
| 205 | func BenchmarkCreateAndClose10Lines(b *testing.B) { |
| 206 | benchCreateAndClose(b, 10) |
no test coverage detected