github.com/jgbaldwinbrown/perf@v0.1.1/benchunit/tidy_test.go (about)

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package benchunit
     6  
     7  import "testing"
     8  
     9  func TestTidy(t *testing.T) {
    10  	test := func(unit, tidied string, factor float64) {
    11  		t.Helper()
    12  		gotFactor, got := Tidy(1, unit)
    13  		if got != tidied || gotFactor != factor {
    14  			t.Errorf("for %s, want *%f %s, got *%f %s", unit, factor, tidied, gotFactor, got)
    15  		}
    16  	}
    17  
    18  	test("ns/op", "sec/op", 1e-9)
    19  	test("x-ns/op", "x-sec/op", 1e-9)
    20  	test("MB/s", "B/s", 1e6)
    21  	test("x-MB/s", "x-B/s", 1e6)
    22  	test("B/op", "B/op", 1)
    23  	test("x-B/op", "x-B/op", 1)
    24  	test("x-allocs/op", "x-allocs/op", 1)
    25  
    26  	test("op/ns", "op/ns", 1)
    27  	test("MB*MB/s", "B*B/s", 1e6*1e6)
    28  	test("MB/MB", "B/MB", 1e6)
    29  }