Skip to content

add Benchmark tests and use strconv instead of fmt.Sprintf for ANSI construction#9

Draft
thaJeztah wants to merge 4 commits intomorikuni:masterfrom
thaJeztah:less_init_step2
Draft

add Benchmark tests and use strconv instead of fmt.Sprintf for ANSI construction#9
thaJeztah wants to merge 4 commits intomorikuni:masterfrom
thaJeztah:less_init_step2

Conversation

@thaJeztah
Copy link
Copy Markdown


add benchmark tests

goos: darwin
goarch: arm64
pkg: github.com/morikuni/aec
cpu: Apple M3 Pro

BenchmarkCursor/0            940589062     1.072 ns/op    0 B/op    0 allocs/op
BenchmarkCursor/2             21112914    64.86 ns/op    20 B/op    2 allocs/op
BenchmarkCursor/20            18367920    70.76 ns/op    21 B/op    2 allocs/op
BenchmarkCursor/200           17084241    70.71 ns/op    24 B/op    2 allocs/op

BenchmarkPosition/0,0         13334660    91.47 ns/op    24 B/op    2 allocs/op
BenchmarkPosition/2,2         13352409    94.05 ns/op    24 B/op    2 allocs/op
BenchmarkPosition/20,20       12992484    94.37 ns/op    24 B/op    2 allocs/op
BenchmarkPosition/200,200     12199471   100.20 ns/op    32 B/op    2 allocs/op
BenchmarkPosition/5,15        12582919    96.98 ns/op    24 B/op    2 allocs/op

BenchmarkScrollUpDown/0      645249318     1.61 ns/op     0 B/op    0 allocs/op
BenchmarkScrollUpDown/2       17620928    69.66 ns/op    20 B/op    2 allocs/op
BenchmarkScrollUpDown/20      17966480    69.91 ns/op    21 B/op    2 allocs/op
BenchmarkScrollUpDown/200     16414399    73.58 ns/op    24 B/op    2 allocs/op

BenchmarkColor3BitF           13825933    83.02 ns/op    21 B/op    2 allocs/op
BenchmarkColor8BitF           13356769    92.91 ns/op    32 B/op    2 allocs/op
BenchmarkFullColorF            9991122   119.50 ns/op    40 B/op    2 allocs/op

PASS
ok   github.com/morikuni/aec    21.156s

use strconv instead of fmt.Sprintf for ANSI construction

Improve performance

goos: darwin
goarch: arm64
pkg: github.com/morikuni/aec
cpu: Apple M3 Pro
                 │  before.txt  │              after.txt              │
                 │    sec/op    │   sec/op     vs base                │
Cursor/0            1.069n ± 5%   1.073n ± 1%        ~ (p=0.402 n=10)
Cursor/2            68.69n ± 2%   28.66n ± 2%  -58.27% (p=0.000 n=10)
Cursor/20           70.09n ± 2%   29.11n ± 2%  -58.47% (p=0.000 n=10)
Cursor/200          72.99n ± 3%   31.43n ± 1%  -56.94% (p=0.000 n=10)
Position/0,0        94.25n ± 3%   12.59n ± 2%  -86.64% (p=0.000 n=10)
Position/2,2        94.14n ± 2%   31.20n ± 2%  -66.86% (p=0.000 n=10)
Position/20,20      93.38n ± 3%   29.48n ± 2%  -68.42% (p=0.000 n=10)
Position/200,200    97.97n ± 2%   36.22n ± 7%  -63.03% (p=0.000 n=10)
Position/5,15       96.52n ± 3%   32.36n ± 2%  -66.47% (p=0.000 n=10)
ScrollUpDown/0      1.669n ± 8%   1.101n ± 3%  -34.05% (p=0.000 n=10)
ScrollUpDown/2      69.02n ± 2%   30.17n ± 1%  -56.30% (p=0.000 n=10)
ScrollUpDown/20     69.69n ± 2%   31.35n ± 2%  -55.02% (p=0.000 n=10)
ScrollUpDown/200    73.78n ± 1%   32.23n ± 5%  -56.32% (p=0.000 n=10)
Color3BitF          88.47n ± 5%   30.39n ± 3%  -65.66% (p=0.000 n=10)
Color8BitF          85.81n ± 8%   34.33n ± 1%  -59.99% (p=0.000 n=10)
FullColorF         113.50n ± 2%   44.19n ± 1%  -61.07% (p=0.000 n=10)
geomean             49.95n        19.87n       -60.22%

                 │  before.txt  │              after.txt               │
                 │     B/op     │    B/op     vs base                  │
Cursor/0           0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/2           20.00 ± 0%     20.00 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/20          21.00 ± 0%     21.00 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/200         24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
Position/0,0       24.00 ± 0%     16.00 ± 0%  -33.33% (p=0.000 n=10)
Position/2,2       24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
Position/20,20     24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
Position/200,200   32.00 ± 0%     32.00 ± 0%        ~ (p=1.000 n=10) ¹
Position/5,15      24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/0     0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/2     20.00 ± 0%     20.00 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/20    21.00 ± 0%     21.00 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/200   24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
Color3BitF         21.00 ± 0%     21.00 ± 0%        ~ (p=1.000 n=10) ¹
Color8BitF         32.00 ± 0%     32.00 ± 0%        ~ (p=1.000 n=10) ¹
FullColorF         40.00 ± 0%     40.00 ± 0%        ~ (p=1.000 n=10) ¹
geomean                       ²                -2.50%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                 │  before.txt  │              after.txt               │
                 │  allocs/op   │ allocs/op   vs base                  │
Cursor/0           0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/2           2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/20          2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/200         2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Position/0,0       2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.000 n=10)
Position/2,2       2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Position/20,20     2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Position/200,200   2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Position/5,15      2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/0     0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/2     2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/20    2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/200   2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Color3BitF         2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Color8BitF         2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
FullColorF         2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
geomean                       ²                -4.24%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

Remove the init functions and instead set the variables directly.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
```
goos: darwin
goarch: arm64
pkg: github.com/morikuni/aec
cpu: Apple M3 Pro

BenchmarkCursor/0            940589062     1.072 ns/op    0 B/op    0 allocs/op
BenchmarkCursor/2             21112914    64.86 ns/op    20 B/op    2 allocs/op
BenchmarkCursor/20            18367920    70.76 ns/op    21 B/op    2 allocs/op
BenchmarkCursor/200           17084241    70.71 ns/op    24 B/op    2 allocs/op

BenchmarkPosition/0,0         13334660    91.47 ns/op    24 B/op    2 allocs/op
BenchmarkPosition/2,2         13352409    94.05 ns/op    24 B/op    2 allocs/op
BenchmarkPosition/20,20       12992484    94.37 ns/op    24 B/op    2 allocs/op
BenchmarkPosition/200,200     12199471   100.20 ns/op    32 B/op    2 allocs/op
BenchmarkPosition/5,15        12582919    96.98 ns/op    24 B/op    2 allocs/op

BenchmarkScrollUpDown/0      645249318     1.61 ns/op     0 B/op    0 allocs/op
BenchmarkScrollUpDown/2       17620928    69.66 ns/op    20 B/op    2 allocs/op
BenchmarkScrollUpDown/20      17966480    69.91 ns/op    21 B/op    2 allocs/op
BenchmarkScrollUpDown/200     16414399    73.58 ns/op    24 B/op    2 allocs/op

BenchmarkColor3BitF           13825933    83.02 ns/op    21 B/op    2 allocs/op
BenchmarkColor8BitF           13356769    92.91 ns/op    32 B/op    2 allocs/op
BenchmarkFullColorF            9991122   119.50 ns/op    40 B/op    2 allocs/op

PASS
ok   github.com/morikuni/aec    21.156s
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Improve performance

```
goos: darwin
goarch: arm64
pkg: github.com/morikuni/aec
cpu: Apple M3 Pro
                 │  before.txt  │              after.txt              │
                 │    sec/op    │   sec/op     vs base                │
Cursor/0            1.069n ± 5%   1.073n ± 1%        ~ (p=0.402 n=10)
Cursor/2            68.69n ± 2%   28.66n ± 2%  -58.27% (p=0.000 n=10)
Cursor/20           70.09n ± 2%   29.11n ± 2%  -58.47% (p=0.000 n=10)
Cursor/200          72.99n ± 3%   31.43n ± 1%  -56.94% (p=0.000 n=10)
Position/0,0        94.25n ± 3%   12.59n ± 2%  -86.64% (p=0.000 n=10)
Position/2,2        94.14n ± 2%   31.20n ± 2%  -66.86% (p=0.000 n=10)
Position/20,20      93.38n ± 3%   29.48n ± 2%  -68.42% (p=0.000 n=10)
Position/200,200    97.97n ± 2%   36.22n ± 7%  -63.03% (p=0.000 n=10)
Position/5,15       96.52n ± 3%   32.36n ± 2%  -66.47% (p=0.000 n=10)
ScrollUpDown/0      1.669n ± 8%   1.101n ± 3%  -34.05% (p=0.000 n=10)
ScrollUpDown/2      69.02n ± 2%   30.17n ± 1%  -56.30% (p=0.000 n=10)
ScrollUpDown/20     69.69n ± 2%   31.35n ± 2%  -55.02% (p=0.000 n=10)
ScrollUpDown/200    73.78n ± 1%   32.23n ± 5%  -56.32% (p=0.000 n=10)
Color3BitF          88.47n ± 5%   30.39n ± 3%  -65.66% (p=0.000 n=10)
Color8BitF          85.81n ± 8%   34.33n ± 1%  -59.99% (p=0.000 n=10)
FullColorF         113.50n ± 2%   44.19n ± 1%  -61.07% (p=0.000 n=10)
geomean             49.95n        19.87n       -60.22%

                 │  before.txt  │              after.txt               │
                 │     B/op     │    B/op     vs base                  │
Cursor/0           0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/2           20.00 ± 0%     20.00 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/20          21.00 ± 0%     21.00 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/200         24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
Position/0,0       24.00 ± 0%     16.00 ± 0%  -33.33% (p=0.000 n=10)
Position/2,2       24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
Position/20,20     24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
Position/200,200   32.00 ± 0%     32.00 ± 0%        ~ (p=1.000 n=10) ¹
Position/5,15      24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/0     0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/2     20.00 ± 0%     20.00 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/20    21.00 ± 0%     21.00 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/200   24.00 ± 0%     24.00 ± 0%        ~ (p=1.000 n=10) ¹
Color3BitF         21.00 ± 0%     21.00 ± 0%        ~ (p=1.000 n=10) ¹
Color8BitF         32.00 ± 0%     32.00 ± 0%        ~ (p=1.000 n=10) ¹
FullColorF         40.00 ± 0%     40.00 ± 0%        ~ (p=1.000 n=10) ¹
geomean                       ²                -2.50%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean

                 │  before.txt  │              after.txt               │
                 │  allocs/op   │ allocs/op   vs base                  │
Cursor/0           0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/2           2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/20          2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Cursor/200         2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Position/0,0       2.000 ± 0%     1.000 ± 0%  -50.00% (p=0.000 n=10)
Position/2,2       2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Position/20,20     2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Position/200,200   2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Position/5,15      2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/0     0.000 ± 0%     0.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/2     2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/20    2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
ScrollUpDown/200   2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Color3BitF         2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
Color8BitF         2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
FullColorF         2.000 ± 0%     2.000 ± 0%        ~ (p=1.000 n=10) ¹
geomean                       ²                -4.24%                ²
¹ all samples are equal
² summaries must be >0 to compute geomean
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant