How to find out the number of CPUs in Go lang?

huangapple go评论74阅读模式
英文:

How to find out the number of CPUs in Go lang?

问题

有没有一种简单的方法可以使用Go语言找出本地计算机上的CPU数量?

英文:

Is there a simple way to find out the number of CPU's on a local machine using Go lang?

答案1

得分: 95

以下是您提供的代码的中文翻译:

package main

import (
	"fmt"
	"runtime"
)

func main() {
	fmt.Println(runtime.NumCPU())
}

这段代码是一个简单的Go程序,它使用了fmtruntime包。在main函数中,它调用了runtime.NumCPU()函数来获取当前系统的CPU核心数,并使用fmt.Println函数将结果打印出来。

英文:

http://play.golang.org/p/cuaf2ZHLIx

package main

import (  
	"fmt"
	"runtime"
)

func main() {
	fmt.Println(runtime.NumCPU())
}

huangapple
  • 本文由 发表于 2014年6月6日 11:23:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/24073697.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定