github.com/minio/madmin-go@v1.7.5/timings_test.go (about) 1 // 2 // MinIO Object Storage (c) 2022 MinIO, Inc. 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 package madmin 18 19 import ( 20 "sort" 21 "testing" 22 ) 23 24 func TestTimings(t *testing.T) { 25 durations := TimeDurations{ 26 4000000, 27 4000000, 28 9000000, 29 9000000, 30 12000000, 31 12000000, 32 14000000, 33 14000000, 34 17000000, 35 17000000, 36 21000000, 37 21000000, 38 36000000, 39 36000000, 40 37000000, 41 37000000, 42 42000000, 43 42000000, 44 54000000, 45 54000000, 46 67000000, 47 67000000, 48 77000000, 49 77000000, 50 88000000, 51 88000000, 52 89000000, 53 89000000, 54 93000000, 55 93000000, 56 } 57 58 sort.Slice(durations, func(i, j int) bool { 59 return int64(durations[i]) < int64(durations[j]) 60 }) 61 62 timings := durations.Measure() 63 if timings.Avg != 44000000 { 64 t.Errorf("Expected 44000000, got %d\n", timings.Avg) 65 } 66 67 if timings.P50 != 37000000 { 68 t.Errorf("Expected 37000000, got %d\n", timings.P50) 69 } 70 71 if timings.P75 != 77000000 { 72 t.Errorf("Expected 77000000, got %d\n", timings.P75) 73 } 74 75 if timings.P95 != 93000000 { 76 t.Errorf("Expected 93000000, got %d\n", timings.P95) 77 } 78 79 if timings.P99 != 93000000 { 80 t.Errorf("Expected 93000000, got %d\n", timings.P99) 81 } 82 83 if timings.P999 != 93000000 { 84 t.Errorf("Expected 93000000, got %d\n", timings.P999) 85 } 86 87 if timings.Long5p != 93000000 { 88 t.Errorf("Expected 93000000, got %d\n", timings.Long5p) 89 } 90 91 if timings.Short5p != 4000000 { 92 t.Errorf("Expected 4000000, got %d\n", timings.Short5p) 93 } 94 95 if timings.Max != 93000000 { 96 t.Errorf("Expected 93000000, got %d\n", timings.Max) 97 } 98 99 if timings.Min != 4000000 { 100 t.Errorf("Expected 4000000, got %d\n", timings.Min) 101 } 102 103 if timings.Range != 89000000 { 104 t.Errorf("Expected 89000000, got %d\n", timings.Range) 105 } 106 107 if timings.StdDev != 30772281 { 108 t.Errorf("Expected abc, got %d\n", timings.StdDev) 109 } 110 }