2018-01-15 23:26:56 +08:00
|
|
|
// 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.
|
|
|
|
|
|
2018-01-16 15:38:53 +08:00
|
|
|
package grpool_test
|
2018-01-15 22:42:58 +08:00
|
|
|
|
|
|
|
|
import (
|
2018-01-17 10:28:42 +08:00
|
|
|
"testing"
|
2018-07-27 15:48:49 +08:00
|
|
|
"runtime"
|
|
|
|
|
"fmt"
|
2018-01-15 22:42:58 +08:00
|
|
|
)
|
|
|
|
|
|
2018-01-16 15:01:36 +08:00
|
|
|
func increment() {
|
2018-07-27 15:48:49 +08:00
|
|
|
for i := 0; i < 100000; i++ {}
|
2018-01-15 22:42:58 +08:00
|
|
|
}
|
|
|
|
|
|
2018-07-27 15:48:49 +08:00
|
|
|
//func Test_GrpoolMemUsage(t *testing.T) {
|
2018-05-25 08:27:17 +08:00
|
|
|
// for i := 0; i < n; i++ {
|
2018-07-27 15:48:49 +08:00
|
|
|
// grpool.Add(increment)
|
2018-05-25 08:27:17 +08:00
|
|
|
// }
|
|
|
|
|
// mem := runtime.MemStats{}
|
|
|
|
|
// runtime.ReadMemStats(&mem)
|
|
|
|
|
// fmt.Println("mem usage:", mem.TotalAlloc/1024)
|
2018-07-27 15:48:49 +08:00
|
|
|
//}
|
|
|
|
|
|
|
|
|
|
func Test_GroroutineMemUsage(t *testing.T) {
|
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
|
go increment()
|
|
|
|
|
}
|
|
|
|
|
mem := runtime.MemStats{}
|
|
|
|
|
runtime.ReadMemStats(&mem)
|
|
|
|
|
fmt.Println("mem usage:", mem.TotalAlloc/1024)
|
|
|
|
|
}
|