portlist: reuse bufio.Reader between files

name         old time/op    new time/op    delta
ListPorts-6    1.18ms ± 5%    1.16ms ± 5%     ~     (p=0.075 n=10+10)

name         old alloc/op   new alloc/op   delta
ListPorts-6    27.2kB ± 0%    14.9kB ± 0%  -45.14%  (p=0.001 n=8+9)

name         old allocs/op  new allocs/op  delta
ListPorts-6      90.0 ± 0%      84.0 ± 0%   -6.67%  (p=0.000 n=10+10)

Updates tailscale/corp#2566

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick
2021-09-12 21:16:03 -07:00
committed by Brad Fitzpatrick
parent 5a9d977c78
commit 61f201f33d
2 changed files with 21 additions and 8 deletions

View File

@ -129,3 +129,13 @@ func BenchmarkParsePorts(b *testing.B) {
}
}
}
func BenchmarkListPorts(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_, err := listPorts()
if err != nil {
b.Fatal(err)
}
}
}