git.sr.ht/~pingoo/stdx@v0.0.0-20240218134121-094174641f6e/validate/numerics_benchmark_test.go (about) 1 package validate 2 3 import "testing" 4 5 func BenchmarkAbs(b *testing.B) { 6 b.ResetTimer() 7 8 for n := 0; n < b.N; n++ { 9 _ = Abs(-123.3e1) 10 } 11 } 12 13 func BenchmarkSign(b *testing.B) { 14 b.ResetTimer() 15 16 for n := 0; n < b.N; n++ { 17 _ = Sign(-123.3e1) 18 } 19 } 20 21 func BenchmarkIsNegative(b *testing.B) { 22 b.ResetTimer() 23 24 for n := 0; n < b.N; n++ { 25 _ = IsNegative(-123.3e1) 26 } 27 } 28 29 func BenchmarkIsPositive(b *testing.B) { 30 b.ResetTimer() 31 32 for n := 0; n < b.N; n++ { 33 _ = IsPositive(-123.3e1) 34 } 35 } 36 37 func BenchmarkIsNonNegative(b *testing.B) { 38 b.ResetTimer() 39 40 for n := 0; n < b.N; n++ { 41 _ = IsNonNegative(-123.3e1) 42 } 43 } 44 45 func BenchmarkIsNonPositive(b *testing.B) { 46 b.ResetTimer() 47 48 for n := 0; n < b.N; n++ { 49 _ = IsNonPositive(-123.3e1) 50 } 51 } 52 53 func BenchmarkInRangeInt(b *testing.B) { 54 b.ResetTimer() 55 56 for n := 0; n < b.N; n++ { 57 _ = InRangeInt(10, -100, 100) 58 } 59 } 60 61 func BenchmarkInRangeFloat32(b *testing.B) { 62 b.ResetTimer() 63 64 for n := 0; n < b.N; n++ { 65 _ = InRangeFloat32(10, -100, 100) 66 } 67 } 68 69 func BenchmarkInRangeFloat64(b *testing.B) { 70 b.ResetTimer() 71 72 for n := 0; n < b.N; n++ { 73 _ = InRangeFloat64(10, -100, 100) 74 } 75 } 76 77 func BenchmarkInRange(b *testing.B) { 78 b.ResetTimer() 79 80 for n := 0; n < b.N; n++ { 81 _ = InRange("abc", "a", "cba") 82 } 83 } 84 85 func BenchmarkIsWhole(b *testing.B) { 86 b.ResetTimer() 87 88 for n := 0; n < b.N; n++ { 89 _ = IsWhole(123.132) 90 } 91 } 92 93 func BenchmarkIsNatural(b *testing.B) { 94 b.ResetTimer() 95 96 for n := 0; n < b.N; n++ { 97 _ = IsNatural(123.132) 98 } 99 }