|
@@ -137,6 +137,18 @@ func BenchmarkLine(b *testing.B) {
|
|
|
line.Output()
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+func BenchmarkLineUnicode(b *testing.B) {
|
|
|
+ Unicode = true
|
|
|
+
|
|
|
+ for n := 0; n < b.N; n++ {
|
|
|
+ var lineBuff *bytes.Buffer = &bytes.Buffer{}
|
|
|
+ fmt.Fprintf(lineBuff, "Line %d of %d", n, b.N)
|
|
|
+ // lineBuff.WriteString(fmt.Sprintf("Line %d of %d", n, b.N))
|
|
|
+ var line *Line = &Line{Text: lineBuff}
|
|
|
+ line.Output()
|
|
|
+ }
|
|
|
+}
|
|
|
func BenchmarkLineColor(b *testing.B) {
|
|
|
Unicode = false
|
|
|
color := ColorText("BRI WHI ON BLUE")
|
|
@@ -204,7 +216,7 @@ func BenchmarkLineUpdate(b *testing.B) {
|
|
|
u.WriteString(" of ")
|
|
|
printd(int64(b.N), u)
|
|
|
*/
|
|
|
- fmt.Fprintf(u, "Line %d of %d", n, b.N)
|
|
|
+ fmt.Fprintf(u, "Line # %d of %d", n, b.N)
|
|
|
}
|
|
|
line.Update()
|
|
|
|
|
@@ -214,6 +226,29 @@ func BenchmarkLineUpdate(b *testing.B) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func BenchmarkLineUpdateUnicode(b *testing.B) {
|
|
|
+ Unicode = true
|
|
|
+ var line *Line = &Line{}
|
|
|
+ var n int
|
|
|
+
|
|
|
+ line.UpdateF = func(u *bytes.Buffer) {
|
|
|
+ u.Reset()
|
|
|
+ /*
|
|
|
+ u.WriteString("Line ")
|
|
|
+ printd(int64(n), u)
|
|
|
+ u.WriteString(" of ")
|
|
|
+ printd(int64(b.N), u)
|
|
|
+ */
|
|
|
+ // № \u2116
|
|
|
+ fmt.Fprintf(u, "Line № %d of %d", n, b.N)
|
|
|
+ }
|
|
|
+ line.Update()
|
|
|
+
|
|
|
+ for n = 0; n < b.N; n++ {
|
|
|
+ line.Update()
|
|
|
+ line.Output()
|
|
|
+ }
|
|
|
+}
|
|
|
func BenchmarkLineRender(b *testing.B) {
|
|
|
Unicode = false
|
|
|
var rf ColorRender = RenderUppercase("RED", "GREEN")
|
|
@@ -226,6 +261,19 @@ func BenchmarkLineRender(b *testing.B) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+func BenchmarkLineRenderUnicode(b *testing.B) {
|
|
|
+ Unicode = true
|
|
|
+ var rf ColorRender = RenderUppercase("RED", "GREEN")
|
|
|
+ // ₿ /u208f
|
|
|
+ var line *Line = NewLine("ThIs Is CrAzY ₿ TeXt HeRe")
|
|
|
+ line.RenderF = rf
|
|
|
+ var n int
|
|
|
+
|
|
|
+ for n = 0; n < b.N; n++ {
|
|
|
+ line.Output()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
// Benchmarks / profiling
|
|
|
|
|
|
// BenchmarkLineColor-4 2868162 403.9 ns/op 8 B/op 0 allocs/op
|
|
@@ -233,7 +281,71 @@ func BenchmarkLineRender(b *testing.B) {
|
|
|
// No change making Color strings to []byte. (reverted change)
|
|
|
|
|
|
func BenchmarkLineRenderUpdate(b *testing.B) {
|
|
|
+ Unicode = false
|
|
|
+ var Up = ColorText("BLUE")
|
|
|
+ var Down = ColorText("BOLD BLUE")
|
|
|
+ var Num = ColorText("BRI GREEN")
|
|
|
+ var Sym = ColorText("CYAN")
|
|
|
+
|
|
|
+ var render = func(output *bytes.Buffer, text []byte) {
|
|
|
+ output.Reset()
|
|
|
+ var last *string
|
|
|
+ // var r Render = Render{Line: text}
|
|
|
+
|
|
|
+ for _, letter := range text {
|
|
|
+ if unicode.IsUpper(rune(letter)) {
|
|
|
+ if last != &Up {
|
|
|
+ output.WriteString(Up)
|
|
|
+ last = &Up
|
|
|
+ }
|
|
|
+ // r.Append(Up, 1)
|
|
|
+ } else if unicode.IsLower(rune(letter)) {
|
|
|
+ if last != &Down {
|
|
|
+ output.WriteString(Down)
|
|
|
+ last = &Down
|
|
|
+ }
|
|
|
+ // r.Append(Down, 1)
|
|
|
+ } else if unicode.IsDigit(rune(letter)) {
|
|
|
+ if last != &Num {
|
|
|
+ output.WriteString(Num)
|
|
|
+ last = &Num
|
|
|
+ }
|
|
|
+ // r.Append(Num, 1)
|
|
|
+ } else {
|
|
|
+ if last != &Sym {
|
|
|
+ output.WriteString(Sym)
|
|
|
+ last = &Sym
|
|
|
+ }
|
|
|
+ //r.Append(Sym, 1)
|
|
|
+ }
|
|
|
+ output.WriteByte(letter)
|
|
|
+ // output.WriteString(string(letter))
|
|
|
+ }
|
|
|
+ // return output.Bytes()
|
|
|
+ // return r.Result
|
|
|
+ }
|
|
|
+
|
|
|
+ var up int
|
|
|
+ var updater = func(u *bytes.Buffer) {
|
|
|
+ u.Reset()
|
|
|
+ fmt.Fprintf(u, "The Value: %d", up)
|
|
|
+ // u.WriteString("The Value: ")
|
|
|
+ // u.WriteString(strconv.Itoa(up))
|
|
|
+ up++
|
|
|
+ // return fmt.Sprintf("The Value: %d", up)
|
|
|
+ }
|
|
|
+ var line *Line = &Line{UpdateF: updater,
|
|
|
+ RenderF: render,
|
|
|
+ Width: 18}
|
|
|
|
|
|
+ for i := 0; i < b.N; i++ {
|
|
|
+ line.Update()
|
|
|
+ line.Output()
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+func BenchmarkLineRenderUpdateUnicode(b *testing.B) {
|
|
|
+ Unicode = true
|
|
|
var Up = ColorText("BLUE")
|
|
|
var Down = ColorText("BOLD BLUE")
|
|
|
var Num = ColorText("BRI GREEN")
|