github.com/TeaOSLab/EdgeNode@v1.3.8/internal/caches/utils_test.go (about)

     1  // Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
     2  
     3  package caches_test
     4  
     5  import (
     6  	"fmt"
     7  	"github.com/TeaOSLab/EdgeNode/internal/caches"
     8  	"github.com/cespare/xxhash/v2"
     9  	"github.com/iwind/TeaGo/types"
    10  	"strconv"
    11  	"testing"
    12  )
    13  
    14  func TestParseHost(t *testing.T) {
    15  	for _, u := range []string{
    16  		"https://goedge.cn/hello/world",
    17  		"https://goedge.cn:8080/hello/world",
    18  		"https://goedge.cn/hello/world?v=1&t=123",
    19  		"https://[::1]:1234/hello/world?v=1&t=123",
    20  		"https://[::1]/hello/world?v=1&t=123",
    21  		"https://127.0.0.1/hello/world?v=1&t=123",
    22  		"https:/hello/world?v=1&t=123",
    23  		"123456",
    24  	} {
    25  		t.Log(u, "=>", caches.ParseHost(u))
    26  	}
    27  }
    28  
    29  func TestUintString(t *testing.T) {
    30  	t.Log(strconv.FormatUint(xxhash.Sum64String("https://goedge.cn/"), 10))
    31  	t.Log(strconv.FormatUint(123456789, 10))
    32  	t.Logf("%d", 1234567890123)
    33  }
    34  
    35  func BenchmarkUint_String(b *testing.B) {
    36  	for i := 0; i < b.N; i++ {
    37  		_ = strconv.FormatUint(1234567890123, 10)
    38  	}
    39  }
    40  
    41  func BenchmarkUint_String2(b *testing.B) {
    42  	for i := 0; i < b.N; i++ {
    43  		_ = types.String(1234567890123)
    44  	}
    45  }
    46  
    47  func BenchmarkUint_String3(b *testing.B) {
    48  	for i := 0; i < b.N; i++ {
    49  		_ = fmt.Sprintf("%d", 1234567890123)
    50  	}
    51  }