diff --git a/README.md b/README.md index a0d646b..c656a75 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,32 @@ All the tasks submitted to ants pool will not be guaranteed to be processed in o The test data above is a basic benchmark and the more detailed benchmarks will be uploaded later. +### Benchmarks with Pool + +![](https://github.com/panjf2000/ants/blob/master/benchmark_pool.png) + + + +### Benchmarks with PoolWithFunc + +![](https://github.com/panjf2000/ants/blob/master/ants_bench_poolwithfunc.png) + +### Throughput + +#### 10w tasks + +![](https://github.com/panjf2000/ants/blob/master/ants_bench_10w.png) + +#### 100w tasks + +![](https://github.com/panjf2000/ants/blob/master/ants_bench_100w.png) + +#### 1000W tasks + +![](https://github.com/panjf2000/ants/blob/master/ants_bench_1000w.png) + +There was only the test of `ants` Pool because my computer was crash when it reached 1000w goroutines. ba + [1]: https://godoc.org/github.com/panjf2000/ants?status.svg [2]: https://godoc.org/github.com/panjf2000/ants [3]: https://goreportcard.com/badge/github.com/panjf2000/ants diff --git a/ants_bench_1000w.png b/ants_bench_1000w.png new file mode 100644 index 0000000..c1b3034 Binary files /dev/null and b/ants_bench_1000w.png differ diff --git a/ants_bench_100w.png b/ants_bench_100w.png new file mode 100644 index 0000000..8ee4529 Binary files /dev/null and b/ants_bench_100w.png differ diff --git a/ants_bench_10w.png b/ants_bench_10w.png new file mode 100644 index 0000000..4c59e64 Binary files /dev/null and b/ants_bench_10w.png differ diff --git a/ants_bench_poolwithfunc.png b/ants_bench_poolwithfunc.png new file mode 100644 index 0000000..2c683e2 Binary files /dev/null and b/ants_bench_poolwithfunc.png differ diff --git a/ants_benchmark_test.go b/ants_benchmark_test.go index 06fdcd3..88470ed 100644 --- a/ants_benchmark_test.go +++ b/ants_benchmark_test.go @@ -32,20 +32,21 @@ import ( const ( _ = 1 << (10 * iota) - KiB // 1024 - MiB // 1048576 - GiB // 1073741824 - TiB // 1099511627776 (超过了int32的范围) - PiB // 1125899906842624 - EiB // 1152921504606846976 - ZiB // 1180591620717411303424 (超过了int64的范围) - YiB // 1208925819614629174706176 + KiB // 1024 + MiB // 1048576 + GiB // 1073741824 + TiB // 1099511627776 (超过了int32的范围) + PiB // 1125899906842624 + EiB // 1152921504606846976 + ZiB // 1180591620717411303424 (超过了int64的范围) + YiB // 1208925819614629174706176 ) const RunTimes = 10000000 const loop = 10 func demoFunc() error { - time.Sleep(loop * time.Millisecond) + n := 10 + time.Sleep(time.Duration(n) * time.Millisecond) return nil } @@ -95,17 +96,18 @@ func BenchmarkAntsPoolWithFunc(b *testing.B) { func BenchmarkGoroutine(b *testing.B) { for i := 0; i < b.N; i++ { for j := 0; j < RunTimes; j++ { - go demoFunc() + go demoPoolFunc(loop) } } - } func BenchmarkAntsPool(b *testing.B) { + p, _ := ants.NewPoolWithFunc(50000, demoPoolFunc) + b.ResetTimer() for i := 0; i < b.N; i++ { for j := 0; j < RunTimes; j++ { - ants.Submit(demoFunc) + p.Serve(loop) } - b.Logf("running goroutines: %d", ants.Running()) + // b.Logf("running goroutines: %d", p.Running()) } } diff --git a/ants_test.go b/ants_test.go index 71e4493..2334e42 100644 --- a/ants_test.go +++ b/ants_test.go @@ -30,7 +30,7 @@ import ( "github.com/panjf2000/ants" ) -var n = 10000000 +var n = 1000000 func TestDefaultPool(t *testing.T) { var wg sync.WaitGroup diff --git a/benchmark_pool.png b/benchmark_pool.png new file mode 100644 index 0000000..2188bf0 Binary files /dev/null and b/benchmark_pool.png differ