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
+14.5k Golang : Find smallest number in array
+25k Golang : How to verify uploaded file is image or allowed file types
+5k Fix sudo yum hang problem with no output or error messages
+14.2k CodeIgniter/PHP : Create directory if does not exist example
+6.5k nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
+14.6k Golang : Implement getters and setters
+6.1k Golang : Generate Datamatrix barcode
+11.1k Golang : Get HTTP protocol version example
+5.8k Golang : How to find out similarity between two strings with Jaro-Winkler Distance?
+16.5k Golang : Read input from console line
+16.3k Golang : Archive directory with tar and gzip
+4k Golang & Javascript : How to save cropped image to file on server