MCPcopy
hub / github.com/micro-editor/micro / benchEdit

Function benchEdit

internal/buffer/buffer_test.go:152–203  ·  view source on GitHub ↗
(testingB *testing.B, nLines, nCursors int)

Source from the content-addressed store, hash-verified

150}
151
152func 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
205func BenchmarkCreateAndClose10Lines(b *testing.B) {
206 benchCreateAndClose(b, 10)

Calls 15

SetSelectionStartMethod · 0.95
SetSelectionEndMethod · 0.95
DeleteSelectionMethod · 0.95
CharacterCountInStringFunction · 0.92
NewBufferFromStringFunction · 0.85
randomTextFunction · 0.85
NewCursorFunction · 0.85
LineMethod · 0.80
SetCursorsMethod · 0.80
AddCursorMethod · 0.80
SetCurCursorMethod · 0.80
PeekMethod · 0.80

Tested by

no test coverage detected