代码拉取完成,页面将自动刷新
package GPool
import (
"fmt"
"net/http"
_ "net/http/pprof"
"sync"
"testing"
"time"
)
func add(args ...interface{}) {
//if len(args) != 2 {
// return
//}
a := args[0].(int)
b := args[1].(int)
fmt.Println("a =",a," b =", b," a + b =", a + b)
time.Sleep(1 * time.Second)
}
func TestGoPool(t *testing.T) {
pool := NewGoPool(100)
now := time.Now()
for i := 0; i < 50; i++ {
for j := 0; j < 50; j++ {
go pool.AddTask(add, []interface{}{i, j})
}
}
pool.Run2()
pool.Wait()
pool.Close()
fmt.Println(time.Now().Sub(now))
}
func TestPProf(t *testing.T) {
go func(){
for {
TestGoPool(t)
}
}()
http.ListenAndServe("0.0.0.0:6060", nil)
}
func TestGoPoolFortaskChain(t *testing.T) {
pool := NewPoolForTaskChain(100)
now := time.Now()
for i := 0; i < 50; i++ {
for j := 0; j < 50; j++ {
pool.AddTaskToTQ(add, []interface{}{i, j})
}
}
pool.Run_taskChain()
fmt.Println(time.Now().Sub(now))
}
type sub struct {
a, b int
}
func (s *sub) Do() {
fmt.Println(s.a + s.b)
time.Sleep(1 * time.Second)
}
func TestWorkPool(t *testing.T) {
pool := NewWorkPool(100)
now := time.Now()
var wg sync.WaitGroup
for i := 0; i < 50; i++ {
for j := 0; j < 50; j++ {
wg.Add(1)
np := &sub{
a: i,
b: j,
}
go func() {
pool.Run(np)
wg.Done()
}()
}
}
wg.Wait()
pool.Close()
fmt.Println(time.Now().Sub(now))
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。