Skip to content

Commit

Permalink
size_test: add parseSize benchmark
Browse files Browse the repository at this point in the history
Shows on my laptop (6 iterations processed by benchstat):

name         time/op
ParseSize-4  10.6µs ± 3%

name         alloc/op
ParseSize-4  3.26kB ± 0%

name         allocs/op
ParseSize-4    72.0 ± 0%

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed May 16, 2022
1 parent af07f36 commit 1d23ffa
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions size_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,18 @@ func TestRAMInBytes(t *testing.T) {
assertError(t, RAMInBytes, "32bm")
}

func BenchmarkParseSize(b *testing.B) {
for i := 0; i < b.N; i++ {
for _, s := range []string{
"", "32", "32b", "32 B", "32k", "32.5 K", "32kb", "32 Kb",
"32.8Mb", "32.9Gb", "32.777Tb", "32Pb", "0.3Mb", "-1",
} {
FromHumanSize(s)
RAMInBytes(s)
}
}
}

func assertEquals(t *testing.T, expected, actual interface{}) {
if expected != actual {
t.Errorf("Expected '%v' but got '%v'", expected, actual)
Expand Down

0 comments on commit 1d23ffa

Please sign in to comment.