Golang : Get number of CPU cores
Problem :
You want to find the maximum number of CPU cores to maximize performance.
Solution :
Use the runtime package to find out the number of CPU cores available on local machine.
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)
}
Reference :
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+15.8k Golang : Get digits from integer before and after given position example
+6.6k Golang : When to use make or new?
+7.6k Golang : Convert(cast) io.Reader type to string
+12.8k Golang : Convert IPv4 address to packed 32-bit binary format
+34.6k Golang : How to stream file to client(browser) or write to http.ResponseWriter?
+10.9k Golang : Create Temporary File
+8.7k Golang : Take screen shot of browser with JQuery example
+14.8k Golang : How to check for empty array string or string?
+4.8k Golang : A program that contain another program and executes it during run-time
+14k Golang : Fix cannot use buffer (type bytes.Buffer) as type io.Writer(Write method has pointer receiver) error
+21.1k Golang : How to force compile or remove object files first before rebuild?
+29.3k Golang : Saving(serializing) and reading file with GOB