完善grpool测试脚本

This commit is contained in:
John
2018-01-17 10:28:42 +08:00
parent b9dd892a05
commit 0d56885726
3 changed files with 76 additions and 29 deletions

View File

@ -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()
// }
//}
}

View 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()
}
}

View 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()
}
}