mirror of
https://gitee.com/johng/gf
synced 2026-06-25 09:15:41 +08:00
完善grpool测试脚本
This commit is contained in:
@ -4,30 +4,27 @@
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://gitee.com/johng/gf.
|
||||
|
||||
// go test *.go -bench=".*"
|
||||
|
||||
package grpool_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"runtime"
|
||||
"fmt"
|
||||
"runtime"
|
||||
"testing"
|
||||
"gitee.com/johng/gf/g/os/grpool"
|
||||
)
|
||||
|
||||
var n = 5000000
|
||||
|
||||
func increment() {
|
||||
for i := 0; i < 1000000; i++ {}
|
||||
}
|
||||
|
||||
//func Test_GrpoolMemUsage(t *testing.T) {
|
||||
// for i := 0; i < n; i++ {
|
||||
// grpool.Add(increment)
|
||||
// }
|
||||
// mem := runtime.MemStats{}
|
||||
// runtime.ReadMemStats(&mem)
|
||||
// fmt.Println("mem usage:", mem.TotalAlloc/1024)
|
||||
//}
|
||||
func Test_GrpoolMemUsage(t *testing.T) {
|
||||
for i := 0; i < n; i++ {
|
||||
grpool.Add(increment)
|
||||
}
|
||||
mem := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&mem)
|
||||
fmt.Println("mem usage:", mem.TotalAlloc/1024)
|
||||
}
|
||||
|
||||
func Test_GroroutineMemUsage(t *testing.T) {
|
||||
for i := 0; i < n; i++ {
|
||||
@ -36,18 +33,4 @@ func Test_GroroutineMemUsage(t *testing.T) {
|
||||
mem := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&mem)
|
||||
fmt.Println("mem usage:", mem.TotalAlloc/1024)
|
||||
}
|
||||
|
||||
//func BenchmarkGrpool(b *testing.B) {
|
||||
// b.N = n
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// grpool.Add(increment)
|
||||
// }
|
||||
//}
|
||||
|
||||
//func BenchmarkGoroutine(b *testing.B) {
|
||||
// b.N = n
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// go increment()
|
||||
// }
|
||||
//}
|
||||
}
|
||||
30
g/os/grpool/grpool_testb1_test.go
Normal file
30
g/os/grpool/grpool_testb1_test.go
Normal file
@ -0,0 +1,30 @@
|
||||
// Copyright 2017 gf Author(https://gitee.com/johng/gf). 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://gitee.com/johng/gf.
|
||||
|
||||
// go test *.go -bench=".*"
|
||||
|
||||
package grpool_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"gitee.com/johng/gf/g/os/grpool"
|
||||
)
|
||||
|
||||
func increment1() {
|
||||
for i := 0; i < 1000000; i++ {}
|
||||
}
|
||||
|
||||
func BenchmarkGrpool_1(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
grpool.Add(increment1)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGoroutine_1(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
go increment1()
|
||||
}
|
||||
}
|
||||
34
g/os/grpool/grpool_testb2_test.go
Normal file
34
g/os/grpool/grpool_testb2_test.go
Normal file
@ -0,0 +1,34 @@
|
||||
// Copyright 2017 gf Author(https://gitee.com/johng/gf). 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://gitee.com/johng/gf.
|
||||
|
||||
// go test *.go -bench=".*" -count=1
|
||||
|
||||
package grpool_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"gitee.com/johng/gf/g/os/grpool"
|
||||
)
|
||||
|
||||
var n = 500000
|
||||
|
||||
func increment2() {
|
||||
for i := 0; i < 1000000; i++ {}
|
||||
}
|
||||
|
||||
func BenchmarkGrpool2(b *testing.B) {
|
||||
b.N = n
|
||||
for i := 0; i < b.N; i++ {
|
||||
grpool.Add(increment)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkGoroutine2(b *testing.B) {
|
||||
b.N = n
|
||||
for i := 0; i < b.N; i++ {
|
||||
go increment()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user