goalng代码
func add(i,len int, ch chan int) {
count := 0
for i:=i; i<len; i++{
count = count + i
}
ch <- count
}
func (u *UserController) Index() {
t1 := time.Now()
fmt.Printf("开始时间:%s,\n",t1)
NCPU := runtime.NumCPU()
gorun := 20
runtime.GOMAXPROCS(NCPU)
chs := make([] chan int,gorun)
for i := 0; i<gorun; i++ {
chs[i] = make(chan int)
n := 20 /gorun
go add(i*n,n*(i+1),chs[i])
}
count := 0
for i2:=0; i2<gorun ; i2++ {
ch := <- chs[i2]
count = count + ch
}
uid,err:= u.GetInt("uid")
if err != nil {
fmt.Print("参数错误\n")
}
userInfo := models.NewUser().UserAll(uid)
josnUser,err := json.Marshal(userInfo)
//fmt.Print(userInfo)
fmt.Print(userInfo)
fmt.Print(josnUser)
//fmt.Printf("接受到uid为:%d,\n",uid)
//fmt.Printf("cpu num:%d,count:%d\n",NCPU,count)
//fmt.Print("我是一个顽强的小强\n")
//admin := u.Get()
u.Data["Website"] = count
u.Data["Email"] = "astaxie@gmail.com111111"
u.TplName = "index.tpl"
}