Go ã§ã®ç°¡å㪠Makefile ã®æ¸ãæ¹
include $(GOROOT)/src/Make.$(GOARCH) TARG=ã³ãã³ãå GOFILES=\ file1.go\ file2.go\ ... include $(GOROOT)/src/Make.cmd
ãããªæãã®ãç¨æããã ãã§ããããããæå¾ã® Make.cmd ã Make.pkg ã«ãã㨠.a ãä½ã£ã¦ããããããã¡ãï¼
Go ã§ç¡é§ã«ãã£ã³ãã«ã使ã£ã¦ã¯ã¤ãã¯ã½ã¼ãã®ãããªãã®ãæ¸ãã¦ã¿ã
-1ãEOFçãªç¨éã§ä½¿ããã¦ããæããCore i7ã§CPU100%ã¾ã§ããé£ããªããã ãã©ãæ¸ãæ¹ãæªãã®ããããããã®ãªã®ãããã¥ã¼ããªã¢ã«ã®sieveã§è奮ãã¦é©å½ã«æ¸ããã ããªã®ã§ãææ¥ããå°ãããã¥ã¡ã³ãèªãã§ã¿ãã¼ã
package main import "fmt" import "rand" import "time" type Callback func (int); func foreach(a chan int, f Callback) { for { v := <-a; if v < 0 { return } else { f(v) } } } func partition(x int, a chan int) (chan int, chan int) { l := make(chan int); h := make(chan int); go func() { foreach(a, func (v int) { if x >= v { l <- v } else { h <- v } }); l <- -1; h <- -1 }(); return l, h } func qsort(a chan int) chan int { out := make(chan int); go func() { x := <-a; if x < 0 { out <- -1; return } l, h := partition(x, a); l = qsort(l); h = qsort(h); foreach(l, func (v int) { out <- v }); out <- x; foreach(h, func (v int) { out <- v }); out <- -1 }(); return out } func main() { rand.Seed(time.Seconds()); a := make(chan int); go func() { for i := 0; i < 100000; i++ { a <- rand.Int(); } a <- -1; }(); res := qsort(a); foreach (res, func (v int) { fmt.Println(v) }); }
runtime.GOMAXPROCS 㧠CPU ããã«æ´»ç¨
CPU使ç¨çã100%ãè¶ããªãã¦æ©ãã§ãã id:kzk ãçºè¦ãã¦ããã¾ããï¼ããã¼ï¼
import "runtime" func main() { runtime.GOMAXPROCS(ã³ã¢æ°); }
ã¨ããæãã«ããã¨æ¬æ°ãåºãã¦ããã¾ãï¼ããä¸ã®ã½ã¼ãã¯ã³ã¢æ°1ã®ã¨ããä¸çªéãã£ãã»ã»ã»ãã¾ããã£ã³ãã«ä½¿ã£ã¦ãããããããªãããä»æ¹ãªãããã©ã»ã»ã»ã
ãã¨ä¸ã®ã½ã¼ãã¯ãã¡ããã¨O(NlogN)ã£ã½ãå®è¡æéã§åãã¦ã¾ããããããããã§ãã¡ã¢ãªãã£ã±ãé£ããã