The previous article wrote very rotten, through the popular science to see the language source realization uses is the quicksort realization bottom order, here imitates, does not spray!
Package Mainimport ("FMT" "Math/rand" "Runtime" "Sort" "time") func mergeonce (L, R []int)] []int {m: = make ([]int, 0, Len (l) +le N (r)) I, J: = 0, 0if i < Len (l) && J < Len (r) {for {if l[i] < L[j] {m = append (M, l[i]) i++if i = = Len (l) { Break}} else {m = append (M, L[j]) j++if j = = Len (r) {break}}}}m = append (Append (M, l[i:] ...), R[j:] ...) Return m}func merge (in Chan []int, Out Chan []int) {var next chan []intvar l] []intfor list: = range in {if L = = nil {L = l Istcontinue}r: = ListIf next = nil {next = make (Chan []int, 1) Go merge (Next, out)}next <-mergeonce (L, r) L = nil}if NE XT = = Nil {out <-L} else {if l! = nil {next <-l}close (next)}}func main () {runtime. Gomaxprocs (2) ch: = Make (chan []int, 1) const Num = 100const Wnum = 100fmt. Println (time. Now ()) go func (n int, out Chan []int) {for i: = 0; i < n; i++ {list: = make ([]int, +) for j: = Range list {List[j] = R and. Int ()}sort. Ints (list) out <-list}close (OFF)} (Num*wnum, ch) out: = Do (chan []int) go merge (ch, out) List: =<-outfmt. Println (time. Now ()) FMT. Println (len (list)) Fmt. Println (sort. intsaresorted (List)}
10 million random number sequencing, how to 24 seconds into 3 seconds? How do I change from 700M memory consumption to 200M?