github.com/minio/madmin-go/v2@v2.2.1/timings_test.go (about) 1 // 2 // Copyright (c) 2015-2022 MinIO, Inc. 3 // 4 // This file is part of MinIO Object Storage stack 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU Affero General Public License as 8 // published by the Free Software Foundation, either version 3 of the 9 // License, or (at your option) any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU Affero General Public License for more details. 15 // 16 // You should have received a copy of the GNU Affero General Public License 17 // along with this program. If not, see <http://www.gnu.org/licenses/>. 18 // 19 20 package madmin 21 22 import ( 23 "sort" 24 "testing" 25 ) 26 27 func TestTimings(t *testing.T) { 28 durations := TimeDurations{ 29 4000000, 30 4000000, 31 9000000, 32 9000000, 33 12000000, 34 12000000, 35 14000000, 36 14000000, 37 17000000, 38 17000000, 39 21000000, 40 21000000, 41 36000000, 42 36000000, 43 37000000, 44 37000000, 45 42000000, 46 42000000, 47 54000000, 48 54000000, 49 67000000, 50 67000000, 51 77000000, 52 77000000, 53 88000000, 54 88000000, 55 89000000, 56 89000000, 57 93000000, 58 93000000, 59 } 60 61 sort.Slice(durations, func(i, j int) bool { 62 return int64(durations[i]) < int64(durations[j]) 63 }) 64 65 timings := durations.Measure() 66 if timings.Avg != 44000000 { 67 t.Errorf("Expected 44000000, got %d\n", timings.Avg) 68 } 69 70 if timings.P50 != 37000000 { 71 t.Errorf("Expected 37000000, got %d\n", timings.P50) 72 } 73 74 if timings.P75 != 77000000 { 75 t.Errorf("Expected 77000000, got %d\n", timings.P75) 76 } 77 78 if timings.P95 != 93000000 { 79 t.Errorf("Expected 93000000, got %d\n", timings.P95) 80 } 81 82 if timings.P99 != 93000000 { 83 t.Errorf("Expected 93000000, got %d\n", timings.P99) 84 } 85 86 if timings.P999 != 93000000 { 87 t.Errorf("Expected 93000000, got %d\n", timings.P999) 88 } 89 90 if timings.Long5p != 93000000 { 91 t.Errorf("Expected 93000000, got %d\n", timings.Long5p) 92 } 93 94 if timings.Short5p != 4000000 { 95 t.Errorf("Expected 4000000, got %d\n", timings.Short5p) 96 } 97 98 if timings.Max != 93000000 { 99 t.Errorf("Expected 93000000, got %d\n", timings.Max) 100 } 101 102 if timings.Min != 4000000 { 103 t.Errorf("Expected 4000000, got %d\n", timings.Min) 104 } 105 106 if timings.Range != 89000000 { 107 t.Errorf("Expected 89000000, got %d\n", timings.Range) 108 } 109 110 if timings.StdDev != 30772281 { 111 t.Errorf("Expected abc, got %d\n", timings.StdDev) 112 } 113 }