mirror of
https://github.com/panjf2000/ants.git
synced 2025-12-18 03:01:01 +00:00
update benchmarks
This commit is contained in:
parent
86325a5f3e
commit
8e7ee16f0d
@ -58,6 +58,40 @@ func demoPoolFunc(args interface{}) error {
|
||||
}
|
||||
|
||||
func BenchmarkGoroutine(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var wg sync.WaitGroup
|
||||
for j := 0; j < RunTimes; j++ {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
demoFunc()
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
mem := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&mem)
|
||||
b.Logf("total memory usage:%dG", mem.TotalAlloc/GiB)
|
||||
}
|
||||
|
||||
func BenchmarkAntsPool(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var wg sync.WaitGroup
|
||||
for j := 0; j < RunTimes; j++ {
|
||||
wg.Add(1)
|
||||
ants.Push(func() {
|
||||
demoFunc()
|
||||
wg.Done()
|
||||
})
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
mem := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&mem)
|
||||
b.Logf("total memory usage:%dG", mem.TotalAlloc/GiB)
|
||||
}
|
||||
|
||||
func BenchmarkGoroutineWithFunc(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var wg sync.WaitGroup
|
||||
b.ResetTimer()
|
||||
@ -69,26 +103,12 @@ func BenchmarkGoroutine(b *testing.B) {
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
mem := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&mem)
|
||||
b.Logf("total memory usage:%dG", mem.TotalAlloc/GiB)
|
||||
}
|
||||
}
|
||||
|
||||
//func BenchmarkAntsPool(b *testing.B) {
|
||||
// for i := 0; i < b.N; i++ {
|
||||
// var wg sync.WaitGroup
|
||||
// for j := 0; j < RunTimes; j++ {
|
||||
// wg.Add(1)
|
||||
// ants.Push(func() {
|
||||
// demoFunc()
|
||||
// wg.Done()
|
||||
// })
|
||||
// }
|
||||
// wg.Wait()
|
||||
// }
|
||||
//}
|
||||
|
||||
func BenchmarkAntsPoolWithFunc(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
var wg sync.WaitGroup
|
||||
@ -103,9 +123,8 @@ func BenchmarkAntsPoolWithFunc(b *testing.B) {
|
||||
p.Serve(loop)
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
mem := runtime.MemStats{}
|
||||
runtime.ReadMemStats(&mem)
|
||||
b.Logf("GB:%d", GiB)
|
||||
b.Logf("total memory usage:%dG", mem.TotalAlloc/GiB)
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user