在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
package main import ( "fmt" "math/rand" "sync" "time" ) func Sleep(arr ...int) (orders []int) { var wg sync.WaitGroup ch := make(chan int, len(arr)) for _, item := range arr { wg.Add(1) go func(sleepTime int) { defer wg.Done() time.Sleep(time.Duration(int64(sleepTime) * time.Hour.Milliseconds())) ch <- sleepTime }(item) } wg.Wait() close(ch) for item := range ch { orders = append(orders, item) } return } func main() { var theArray = []int{-1,10, 1, 18, 30, 23, 12, 7, 5, 18, 14} r := rand.New(rand.NewSource(time.Now().UnixNano())) for i:=0; i<100000; i++ { theArray = append(theArray, r.Intn(1000)) } fmt.Print("排序前") //fmt.Println(theArray) fmt.Print("排序后") _ = Sleep(theArray...) //fmt.Println(res) }
没什么卵用 数字大就慢的要死 |
请发表评论