github.com/gogf/gf/v2@v2.7.4/net/ghttp/ghttp_z_bench_test.go (about) 1 // Copyright GoFrame Author(https://goframe.org). All Rights Reserved. 2 // 3 // This Source Code Form is subject to the terms of the MIT License. 4 // If a copy of the MIT was not distributed with this file, 5 // You can obtain one at https://github.com/gogf/gf. 6 7 package ghttp_test 8 9 import ( 10 "strings" 11 "testing" 12 ) 13 14 func Benchmark_TrimRightCharWithStrings(b *testing.B) { 15 for i := 0; i < b.N; i++ { 16 path := "//////////" 17 strings.TrimRight(path, "/") 18 } 19 } 20 21 func Benchmark_TrimRightCharWithSlice1(b *testing.B) { 22 for i := 0; i < b.N; i++ { 23 path := "//////////" 24 for len(path) > 0 && path[len(path)-1] == '/' { 25 path = path[:len(path)-1] 26 } 27 } 28 } 29 30 func Benchmark_TrimRightCharWithSlice2(b *testing.B) { 31 for i := 0; i < b.N; i++ { 32 path := "//////////" 33 for { 34 if length := len(path); length > 0 && path[length-1] == '/' { 35 path = path[:length-1] 36 } else { 37 break 38 } 39 } 40 } 41 }