Debian Codegraph @

vt/emulate_bench_test.go

raw symbols SCIP
1 // Copyright 2026 The TCell Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package vt
16
17 import (
18 "testing"
19
20 "github.com/gdamore/tcell/v3/color"
21 )
22
23 func BenchmarkPutRuneCurrent(b *testing.B) {
24 benchPutRune(b, "current", (*emulator).putRune)
25 }
26
27 func benchPutRune(b *testing.B, name string, put func(*emulator, rune)) {
28 cases := []struct {
29 name string
30 r rune
31 seq []rune
32 }{
33 {name: "ascii", r: 'a'},
34 {name: "width", r: 'π'},
35 {name: "wide", r: '宽'},
36 {name: "combining", r: '\u0301'},
37 {name: "line", seq: []rune{
38 '\u250C', '\u2510', '\u2514', '\u2518',
39 '\u2500', '\u2502', '\u251C', '\u2524',
40 '\u252C', '\u2534', '\u253C', '\u256D',
41 '\u256E', '\u256F', '\u2570', '\u2571',
42 }},
43 {name: "mixed32", seq: []rune{
44 '\u0416', '\u0414', '\u042E', '\u042F',
45 '\u041F', '\u041B', '\u0424', '\u042B',
46 '\u042D', '\u0411', '\u0413', '\u0428',
47 '\u00E9', '\u00F6', '\u00FC', '\u00F1',
48 '\u00E7', '\u00F8', '\u00E5', '\u00DF',
49 '\u0142', '\u0111', '\u0127', '\u0131',
50 '\U0001F600', '\U0001F680', '\U0001F9EA', '\U0001F525',
51 '\U0001F355', '\U0001F389', '\U0001F4BB', '\U0001F4E6',
52 }},
53 {name: "mixed64", seq: sweepMixedRunes64},
54 }
55
56 for _, tc := range cases {
57 b.Run(name+"/"+tc.name, func(b *testing.B) {
58 em := NewEmulator(NewMockBackend(MockOptSize{X: 8, Y: 1}, MockOptColors(0))).(*emulator)
59 em.style = BaseStyle.WithFg(color.White).WithBg(color.Black)
60 em.defaultStyle = em.style
61 em.localModes[PmGraphemeClusters] = ModeOn
62 em.localModes[PmAutoMargin] = ModeOn
63 em.cells[0].S = em.style
64 em.cells[0].W = 1
65 b.ReportAllocs()
66 b.ResetTimer()
67 for i := 0; i < b.N; i++ {
68 r := tc.r
69 if len(tc.seq) != 0 {
70 r = tc.seq[i%len(tc.seq)]
71 }
72 em.pos = Coord{X: 1, Y: 0}
73 em.lastIndex = 1
74 em.autoWrap = false
75 em.cells[0].C = "e"
76 em.cells[0].S = em.style
77 em.cells[0].W = 1
78 put(em, r)
79 }
80 })
81 }
82 }