mirror of
https://gitee.com/johng/gf.git
synced 2024-12-05 05:37:55 +08:00
42 lines
899 B
Go
42 lines
899 B
Go
// Copyright GoFrame Author(https://goframe.org). All Rights Reserved.
|
|
//
|
|
// This Source Code Form is subject to the terms of the MIT License.
|
|
// If a copy of the MIT was not distributed with this file,
|
|
// You can obtain one at https://github.com/gogf/gf.
|
|
|
|
package ghttp_test
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func Benchmark_TrimRightCharWithStrings(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
path := "//////////"
|
|
path = strings.TrimRight(path, "/")
|
|
}
|
|
}
|
|
|
|
func Benchmark_TrimRightCharWithSlice1(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
path := "//////////"
|
|
for len(path) > 0 && path[len(path)-1] == '/' {
|
|
path = path[:len(path)-1]
|
|
}
|
|
}
|
|
}
|
|
|
|
func Benchmark_TrimRightCharWithSlice2(b *testing.B) {
|
|
for i := 0; i < b.N; i++ {
|
|
path := "//////////"
|
|
for {
|
|
if length := len(path); length > 0 && path[length-1] == '/' {
|
|
path = path[:length-1]
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
}
|
|
}
|