企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
> ### 基准测试(压力测试/性能测试) - 适合单个功能模块 * go test -bench BenchmarkSort1 只压测BenchmarkSort1方法 * go test -bench . 测试该路径下所有压力测试 ~~~ package main import ( "fmt" "math/rand" "testing" "time" ) func BenchmarkSort1(b *testing.B) { fmt.Println("-----TODO1-----") for i := 0; i < b.N; i++ { actionSort() } } func BenchmarkSort2(b *testing.B) { fmt.Println("-----TODO2-----") for i := 0; i < b.N; i++ { actionSort() } } func actionSort() { rand.Seed(time.Now().Unix()) number := make([]int, 30000, 10000000) for k, _ := range number { number[k] = rand.Intn(100) } L := len(number) BubbleSort(number, L) } func BubbleSort(data []int, L int) { t := time.Now() for i := 0; i < L; i++ { for j := i + 1; j < L; j++ { if data[i] > data[j] { data[i], data[j] = data[j], data[i] } } } fmt.Println("BubbleSort - Time:", time.Since(t)) } ~~~