[PR #356] TextView: Add tests and benchmarks #922

Open
opened 2026-03-04 01:08:35 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/rivo/tview/pull/356
Author: @tslocum
Created: 10/18/2019
Status: 🔄 Open

Base: masterHead: tvtests


📝 Commits (1)

  • 4228b76 TextView: Add tests and benchmarks

📊 Changes

1 file changed (+301 additions, -0 deletions)

View changed files

textview_test.go (+301 -0)

📄 Description

Writing and drawing are tested and benchmarked. This was inspired by the request in #266.

Below is an example benchmark run.

goos: linux
goarch: amd64
pkg: github.com/rivo/tview
BenchmarkTextViewWrite/NColorNRegionNScrollNWrapNWordWrap-8         	   53863	     20884 ns/op	    2096 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorNRegionNScrollNWrapYWordWrap-8         	   60584	     20651 ns/op	    2093 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorNRegionNScrollYWrapNWordWrap-8         	   59386	     20386 ns/op	    2093 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorNRegionNScrollYWrapYWordWrap-8         	   58779	     20492 ns/op	    2095 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorNRegionYScrollNWrapNWordWrap-8         	   59598	     20366 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorNRegionYScrollNWrapYWordWrap-8         	   58218	     20363 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorNRegionYScrollYWrapNWordWrap-8         	   60982	     20583 ns/op	    2091 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorNRegionYScrollYWrapYWordWrap-8         	   60794	     20714 ns/op	    2095 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorYRegionNScrollNWrapNWordWrap-8         	   58226	     20757 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorYRegionNScrollNWrapYWordWrap-8         	   57534	     20653 ns/op	    2092 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorYRegionNScrollYWrapNWordWrap-8         	   56761	     20477 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorYRegionNScrollYWrapYWordWrap-8         	   57943	     20665 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorYRegionYScrollNWrapNWordWrap-8         	   59187	     20756 ns/op	    2093 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorYRegionYScrollNWrapYWordWrap-8         	   57775	     20656 ns/op	    2093 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorYRegionYScrollYWrapNWordWrap-8         	   59284	     21571 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/NColorYRegionYScrollYWrapYWordWrap-8         	   58123	     20656 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorNRegionNScrollNWrapNWordWrap-8         	   58440	     21000 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorNRegionNScrollNWrapYWordWrap-8         	   58908	     20676 ns/op	    2092 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorNRegionNScrollYWrapNWordWrap-8         	   56762	     21504 ns/op	    2095 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorNRegionNScrollYWrapYWordWrap-8         	   58995	     21175 ns/op	    2095 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorNRegionYScrollNWrapNWordWrap-8         	   58191	     20733 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorNRegionYScrollNWrapYWordWrap-8         	   55160	     21023 ns/op	    2099 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorNRegionYScrollYWrapNWordWrap-8         	   57406	     21068 ns/op	    2091 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorNRegionYScrollYWrapYWordWrap-8         	   58632	     20896 ns/op	    2095 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorYRegionNScrollNWrapNWordWrap-8         	   55088	     20998 ns/op	    2096 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorYRegionNScrollNWrapYWordWrap-8         	   54990	     21248 ns/op	    2095 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorYRegionNScrollYWrapNWordWrap-8         	   56098	     21086 ns/op	    2093 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorYRegionNScrollYWrapYWordWrap-8         	   57043	     21238 ns/op	    2095 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorYRegionYScrollNWrapNWordWrap-8         	   57566	     20919 ns/op	    2092 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorYRegionYScrollNWrapYWordWrap-8         	   50318	     21054 ns/op	    2094 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorYRegionYScrollYWrapNWordWrap-8         	   57850	     21607 ns/op	    2096 B/op	      13 allocs/op
BenchmarkTextViewWrite/YColorYRegionYScrollYWrapYWordWrap-8         	   58089	     21752 ns/op	    2092 B/op	      13 allocs/op
BenchmarkTextViewDraw/NColorNRegionNScrollNWrapNWordWrap-8          	   10000	    107807 ns/op	   42803 B/op	     300 allocs/op
BenchmarkTextViewDraw/NColorNRegionNScrollNWrapYWordWrap-8          	   10000	    108949 ns/op	   42803 B/op	     300 allocs/op
BenchmarkTextViewDraw/NColorNRegionNScrollYWrapNWordWrap-8          	    2925	    401498 ns/op	   87374 B/op	    1121 allocs/op
BenchmarkTextViewDraw/NColorNRegionNScrollYWrapYWordWrap-8          	    2266	    502294 ns/op	  110592 B/op	    1389 allocs/op
BenchmarkTextViewDraw/NColorNRegionYScrollNWrapNWordWrap-8          	   10000	    106423 ns/op	   42803 B/op	     300 allocs/op
BenchmarkTextViewDraw/NColorNRegionYScrollNWrapYWordWrap-8          	   10000	    106575 ns/op	   42803 B/op	     300 allocs/op
BenchmarkTextViewDraw/NColorNRegionYScrollYWrapNWordWrap-8          	   12841	     93737 ns/op	   21686 B/op	     674 allocs/op
BenchmarkTextViewDraw/NColorNRegionYScrollYWrapYWordWrap-8          	   13597	     89797 ns/op	   21016 B/op	     640 allocs/op
BenchmarkTextViewDraw/NColorYRegionNScrollNWrapNWordWrap-8          	   10000	    110666 ns/op	   44964 B/op	     313 allocs/op
BenchmarkTextViewDraw/NColorYRegionNScrollNWrapYWordWrap-8          	   10000	    111356 ns/op	   44953 B/op	     313 allocs/op
BenchmarkTextViewDraw/NColorYRegionNScrollYWrapNWordWrap-8          	    2995	    408458 ns/op	   89998 B/op	    1165 allocs/op
BenchmarkTextViewDraw/NColorYRegionNScrollYWrapYWordWrap-8          	    2403	    510666 ns/op	  112859 B/op	    1433 allocs/op
BenchmarkTextViewDraw/NColorYRegionYScrollNWrapNWordWrap-8          	   10000	    118059 ns/op	   44998 B/op	     313 allocs/op
BenchmarkTextViewDraw/NColorYRegionYScrollNWrapYWordWrap-8          	   10000	    110340 ns/op	   44994 B/op	     313 allocs/op
BenchmarkTextViewDraw/NColorYRegionYScrollYWrapNWordWrap-8          	   12051	    103014 ns/op	   22620 B/op	     711 allocs/op
BenchmarkTextViewDraw/NColorYRegionYScrollYWrapYWordWrap-8          	   12879	     92987 ns/op	   21959 B/op	     677 allocs/op
BenchmarkTextViewDraw/YColorNRegionNScrollNWrapNWordWrap-8          	   10000	    113543 ns/op	   44898 B/op	     313 allocs/op
BenchmarkTextViewDraw/YColorNRegionNScrollNWrapYWordWrap-8          	   10000	    117098 ns/op	   45006 B/op	     313 allocs/op
BenchmarkTextViewDraw/YColorNRegionNScrollYWrapNWordWrap-8          	    2973	    411109 ns/op	   90030 B/op	    1165 allocs/op
BenchmarkTextViewDraw/YColorNRegionNScrollYWrapYWordWrap-8          	    2437	    507715 ns/op	  112762 B/op	    1433 allocs/op
BenchmarkTextViewDraw/YColorNRegionYScrollNWrapNWordWrap-8          	   10000	    111336 ns/op	   45054 B/op	     313 allocs/op
BenchmarkTextViewDraw/YColorNRegionYScrollNWrapYWordWrap-8          	   10000	    111343 ns/op	   44965 B/op	     313 allocs/op
BenchmarkTextViewDraw/YColorNRegionYScrollYWrapNWordWrap-8          	   10000	    103651 ns/op	   22576 B/op	     711 allocs/op
BenchmarkTextViewDraw/YColorNRegionYScrollYWrapYWordWrap-8          	   12741	     93633 ns/op	   21934 B/op	     677 allocs/op
BenchmarkTextViewDraw/YColorYRegionNScrollNWrapNWordWrap-8          	    9283	    114598 ns/op	   45084 B/op	     317 allocs/op
BenchmarkTextViewDraw/YColorYRegionNScrollNWrapYWordWrap-8          	   10000	    114982 ns/op	   45048 B/op	     317 allocs/op
BenchmarkTextViewDraw/YColorYRegionNScrollYWrapNWordWrap-8          	    2860	    406355 ns/op	   90355 B/op	    1176 allocs/op
BenchmarkTextViewDraw/YColorYRegionNScrollYWrapYWordWrap-8          	    2425	    512630 ns/op	  113260 B/op	    1444 allocs/op
BenchmarkTextViewDraw/YColorYRegionYScrollNWrapNWordWrap-8          	   10000	    113712 ns/op	   45074 B/op	     317 allocs/op
BenchmarkTextViewDraw/YColorYRegionYScrollNWrapYWordWrap-8          	   10000	    114609 ns/op	   45037 B/op	     317 allocs/op
BenchmarkTextViewDraw/YColorYRegionYScrollYWrapNWordWrap-8          	   10000	    103539 ns/op	   22959 B/op	     721 allocs/op
BenchmarkTextViewDraw/YColorYRegionYScrollYWrapYWordWrap-8          	   12092	     97101 ns/op	   22321 B/op	     687 allocs/op
PASS
ok  	github.com/rivo/tview	88.509s

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/rivo/tview/pull/356 **Author:** [@tslocum](https://github.com/tslocum) **Created:** 10/18/2019 **Status:** 🔄 Open **Base:** `master` ← **Head:** `tvtests` --- ### 📝 Commits (1) - [`4228b76`](https://github.com/rivo/tview/commit/4228b766785ed556a1a69b615cf7dbd60cd71510) TextView: Add tests and benchmarks ### 📊 Changes **1 file changed** (+301 additions, -0 deletions) <details> <summary>View changed files</summary> ➕ `textview_test.go` (+301 -0) </details> ### 📄 Description Writing and drawing are tested and benchmarked. This was inspired by the request in #266. Below is an example benchmark run. ``` goos: linux goarch: amd64 pkg: github.com/rivo/tview BenchmarkTextViewWrite/NColorNRegionNScrollNWrapNWordWrap-8 53863 20884 ns/op 2096 B/op 13 allocs/op BenchmarkTextViewWrite/NColorNRegionNScrollNWrapYWordWrap-8 60584 20651 ns/op 2093 B/op 13 allocs/op BenchmarkTextViewWrite/NColorNRegionNScrollYWrapNWordWrap-8 59386 20386 ns/op 2093 B/op 13 allocs/op BenchmarkTextViewWrite/NColorNRegionNScrollYWrapYWordWrap-8 58779 20492 ns/op 2095 B/op 13 allocs/op BenchmarkTextViewWrite/NColorNRegionYScrollNWrapNWordWrap-8 59598 20366 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/NColorNRegionYScrollNWrapYWordWrap-8 58218 20363 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/NColorNRegionYScrollYWrapNWordWrap-8 60982 20583 ns/op 2091 B/op 13 allocs/op BenchmarkTextViewWrite/NColorNRegionYScrollYWrapYWordWrap-8 60794 20714 ns/op 2095 B/op 13 allocs/op BenchmarkTextViewWrite/NColorYRegionNScrollNWrapNWordWrap-8 58226 20757 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/NColorYRegionNScrollNWrapYWordWrap-8 57534 20653 ns/op 2092 B/op 13 allocs/op BenchmarkTextViewWrite/NColorYRegionNScrollYWrapNWordWrap-8 56761 20477 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/NColorYRegionNScrollYWrapYWordWrap-8 57943 20665 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/NColorYRegionYScrollNWrapNWordWrap-8 59187 20756 ns/op 2093 B/op 13 allocs/op BenchmarkTextViewWrite/NColorYRegionYScrollNWrapYWordWrap-8 57775 20656 ns/op 2093 B/op 13 allocs/op BenchmarkTextViewWrite/NColorYRegionYScrollYWrapNWordWrap-8 59284 21571 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/NColorYRegionYScrollYWrapYWordWrap-8 58123 20656 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/YColorNRegionNScrollNWrapNWordWrap-8 58440 21000 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/YColorNRegionNScrollNWrapYWordWrap-8 58908 20676 ns/op 2092 B/op 13 allocs/op BenchmarkTextViewWrite/YColorNRegionNScrollYWrapNWordWrap-8 56762 21504 ns/op 2095 B/op 13 allocs/op BenchmarkTextViewWrite/YColorNRegionNScrollYWrapYWordWrap-8 58995 21175 ns/op 2095 B/op 13 allocs/op BenchmarkTextViewWrite/YColorNRegionYScrollNWrapNWordWrap-8 58191 20733 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/YColorNRegionYScrollNWrapYWordWrap-8 55160 21023 ns/op 2099 B/op 13 allocs/op BenchmarkTextViewWrite/YColorNRegionYScrollYWrapNWordWrap-8 57406 21068 ns/op 2091 B/op 13 allocs/op BenchmarkTextViewWrite/YColorNRegionYScrollYWrapYWordWrap-8 58632 20896 ns/op 2095 B/op 13 allocs/op BenchmarkTextViewWrite/YColorYRegionNScrollNWrapNWordWrap-8 55088 20998 ns/op 2096 B/op 13 allocs/op BenchmarkTextViewWrite/YColorYRegionNScrollNWrapYWordWrap-8 54990 21248 ns/op 2095 B/op 13 allocs/op BenchmarkTextViewWrite/YColorYRegionNScrollYWrapNWordWrap-8 56098 21086 ns/op 2093 B/op 13 allocs/op BenchmarkTextViewWrite/YColorYRegionNScrollYWrapYWordWrap-8 57043 21238 ns/op 2095 B/op 13 allocs/op BenchmarkTextViewWrite/YColorYRegionYScrollNWrapNWordWrap-8 57566 20919 ns/op 2092 B/op 13 allocs/op BenchmarkTextViewWrite/YColorYRegionYScrollNWrapYWordWrap-8 50318 21054 ns/op 2094 B/op 13 allocs/op BenchmarkTextViewWrite/YColorYRegionYScrollYWrapNWordWrap-8 57850 21607 ns/op 2096 B/op 13 allocs/op BenchmarkTextViewWrite/YColorYRegionYScrollYWrapYWordWrap-8 58089 21752 ns/op 2092 B/op 13 allocs/op BenchmarkTextViewDraw/NColorNRegionNScrollNWrapNWordWrap-8 10000 107807 ns/op 42803 B/op 300 allocs/op BenchmarkTextViewDraw/NColorNRegionNScrollNWrapYWordWrap-8 10000 108949 ns/op 42803 B/op 300 allocs/op BenchmarkTextViewDraw/NColorNRegionNScrollYWrapNWordWrap-8 2925 401498 ns/op 87374 B/op 1121 allocs/op BenchmarkTextViewDraw/NColorNRegionNScrollYWrapYWordWrap-8 2266 502294 ns/op 110592 B/op 1389 allocs/op BenchmarkTextViewDraw/NColorNRegionYScrollNWrapNWordWrap-8 10000 106423 ns/op 42803 B/op 300 allocs/op BenchmarkTextViewDraw/NColorNRegionYScrollNWrapYWordWrap-8 10000 106575 ns/op 42803 B/op 300 allocs/op BenchmarkTextViewDraw/NColorNRegionYScrollYWrapNWordWrap-8 12841 93737 ns/op 21686 B/op 674 allocs/op BenchmarkTextViewDraw/NColorNRegionYScrollYWrapYWordWrap-8 13597 89797 ns/op 21016 B/op 640 allocs/op BenchmarkTextViewDraw/NColorYRegionNScrollNWrapNWordWrap-8 10000 110666 ns/op 44964 B/op 313 allocs/op BenchmarkTextViewDraw/NColorYRegionNScrollNWrapYWordWrap-8 10000 111356 ns/op 44953 B/op 313 allocs/op BenchmarkTextViewDraw/NColorYRegionNScrollYWrapNWordWrap-8 2995 408458 ns/op 89998 B/op 1165 allocs/op BenchmarkTextViewDraw/NColorYRegionNScrollYWrapYWordWrap-8 2403 510666 ns/op 112859 B/op 1433 allocs/op BenchmarkTextViewDraw/NColorYRegionYScrollNWrapNWordWrap-8 10000 118059 ns/op 44998 B/op 313 allocs/op BenchmarkTextViewDraw/NColorYRegionYScrollNWrapYWordWrap-8 10000 110340 ns/op 44994 B/op 313 allocs/op BenchmarkTextViewDraw/NColorYRegionYScrollYWrapNWordWrap-8 12051 103014 ns/op 22620 B/op 711 allocs/op BenchmarkTextViewDraw/NColorYRegionYScrollYWrapYWordWrap-8 12879 92987 ns/op 21959 B/op 677 allocs/op BenchmarkTextViewDraw/YColorNRegionNScrollNWrapNWordWrap-8 10000 113543 ns/op 44898 B/op 313 allocs/op BenchmarkTextViewDraw/YColorNRegionNScrollNWrapYWordWrap-8 10000 117098 ns/op 45006 B/op 313 allocs/op BenchmarkTextViewDraw/YColorNRegionNScrollYWrapNWordWrap-8 2973 411109 ns/op 90030 B/op 1165 allocs/op BenchmarkTextViewDraw/YColorNRegionNScrollYWrapYWordWrap-8 2437 507715 ns/op 112762 B/op 1433 allocs/op BenchmarkTextViewDraw/YColorNRegionYScrollNWrapNWordWrap-8 10000 111336 ns/op 45054 B/op 313 allocs/op BenchmarkTextViewDraw/YColorNRegionYScrollNWrapYWordWrap-8 10000 111343 ns/op 44965 B/op 313 allocs/op BenchmarkTextViewDraw/YColorNRegionYScrollYWrapNWordWrap-8 10000 103651 ns/op 22576 B/op 711 allocs/op BenchmarkTextViewDraw/YColorNRegionYScrollYWrapYWordWrap-8 12741 93633 ns/op 21934 B/op 677 allocs/op BenchmarkTextViewDraw/YColorYRegionNScrollNWrapNWordWrap-8 9283 114598 ns/op 45084 B/op 317 allocs/op BenchmarkTextViewDraw/YColorYRegionNScrollNWrapYWordWrap-8 10000 114982 ns/op 45048 B/op 317 allocs/op BenchmarkTextViewDraw/YColorYRegionNScrollYWrapNWordWrap-8 2860 406355 ns/op 90355 B/op 1176 allocs/op BenchmarkTextViewDraw/YColorYRegionNScrollYWrapYWordWrap-8 2425 512630 ns/op 113260 B/op 1444 allocs/op BenchmarkTextViewDraw/YColorYRegionYScrollNWrapNWordWrap-8 10000 113712 ns/op 45074 B/op 317 allocs/op BenchmarkTextViewDraw/YColorYRegionYScrollNWrapYWordWrap-8 10000 114609 ns/op 45037 B/op 317 allocs/op BenchmarkTextViewDraw/YColorYRegionYScrollYWrapNWordWrap-8 10000 103539 ns/op 22959 B/op 721 allocs/op BenchmarkTextViewDraw/YColorYRegionYScrollYWrapYWordWrap-8 12092 97101 ns/op 22321 B/op 687 allocs/op PASS ok github.com/rivo/tview 88.509s ``` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#922
No description provided.