github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/cmd/url_test.go (about) 1 // Copyright (c) 2015-2021 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package cmd 19 20 import ( 21 "net/http" 22 "testing" 23 ) 24 25 func BenchmarkURLQueryForm(b *testing.B) { 26 req, err := http.NewRequest(http.MethodGet, "http://localhost:9000/bucket/name?uploadId=upload&partNumber=1", http.NoBody) 27 if err != nil { 28 b.Fatal(err) 29 } 30 31 // benchmark utility which helps obtain number of allocations and bytes allocated per ops. 32 b.ReportAllocs() 33 // the actual benchmark for PutObject starts here. Reset the benchmark timer. 34 b.ResetTimer() 35 36 if err := req.ParseForm(); err != nil { 37 b.Fatal(err) 38 } 39 40 b.RunParallel(func(pb *testing.PB) { 41 for pb.Next() { 42 req.Form.Get("uploadId") 43 } 44 }) 45 46 // Benchmark ends here. Stop timer. 47 b.StopTimer() 48 } 49 50 // BenchmarkURLQuery - benchmark URL memory allocations 51 func BenchmarkURLQuery(b *testing.B) { 52 req, err := http.NewRequest(http.MethodGet, "http://localhost:9000/bucket/name?uploadId=upload&partNumber=1", http.NoBody) 53 if err != nil { 54 b.Fatal(err) 55 } 56 57 // benchmark utility which helps obtain number of allocations and bytes allocated per ops. 58 b.ReportAllocs() 59 // the actual benchmark for PutObject starts here. Reset the benchmark timer. 60 b.ResetTimer() 61 62 b.RunParallel(func(pb *testing.PB) { 63 for pb.Next() { 64 req.URL.Query().Get("uploadId") 65 } 66 }) 67 68 // Benchmark ends here. Stop timer. 69 b.StopTimer() 70 }