Golang runtime.GOMAXPROCS() and NumCPU() functions example
package runtime
Golang runtime.GOMAXPROCS() and NumCPU() functions usage example
package main
import (
"fmt"
"runtime"
)
func main() {
cores := runtime.NumCPU()
fmt.Printf("This machine has %d CPU cores. \n", cores)
// maximize CPU usage for maximum performance
runtime.GOMAXPROCS(cores)
}
References :
http://golang.org/pkg/runtime/#GOMAXPROCS
http://golang.org/pkg/runtime/#NumCPU
https://www.socketloop.com/tutorials/golang-get-number-of-cpu-cores
Advertisement
Something interesting
Tutorials
+8.3k Golang : Oanda bot with Telegram and RSI example
+9.4k Golang : Launch Mac OS X Preview (or other OS) application from your program example
+25.2k Golang : Storing cookies in http.CookieJar example
+27.6k PHP : Convert(cast) string to bigInt
+9.2k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+15.2k Golang : How to check if IP address is in range
+14k Golang : convert rune to unicode hexadecimal value and back to rune character
+7.4k Golang : Accessing dataframe-go element by row, column and name example
+16.6k Golang : Delete files by extension
+7.1k Restart Apache or Nginx web server without password prompt
+9.9k Golang : Function wrapper that takes arguments and return result example
+12.3k Golang : Print UTF-8 fonts on image example