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
+14.8k Golang : How to reverse elements order in map ?
+13.4k Golang : How to get URL port?
+8.9k Golang : Bcrypting password
+3.9k Facebook : How to place save to Facebook button on your website
+9.3k Golang : Text file editor (accept input from screen and save to file)
+21.2k Golang : Repeat a character by multiple of x factor
+7.8k Golang : Executing and evaluating nested loop in html template
+7k Golang : get the current working directory of a running program
+5.4k Linux/Unix : Commands that you need to be careful about
+5.1k Fontello : How to load and use fonts?
+4.4k Golang : Get FX sentiment from website example
+29.4k Golang : How to redirect to new page with net/http?