您尚未登录。

楼主 #1 2019-11-08 00:28:12

kekemuyu
会员
注册时间: 2018-12-13
已发帖子: 849
积分: 710

燃烧吧cpu(go语言版cpuburn)

适用于能交叉编译go的各种平台,原来cpuburn就是让cpu傻傻空转。
https://github.com/patrickmn/cpuburn/blob/master/cpuburn.go

package main

import (
	"flag"
	"fmt"
	"runtime"
	"time"
)

var (
	numBurn        int
	updateInterval int
)

func cpuBurn() {
	for {
		for i := 0; i < 2147483647; i++ {
		}
		runtime.Gosched()
	}
}

func init() {
	flag.IntVar(&numBurn, "n", 0, "number of cores to burn (0 = all)")
	flag.IntVar(&updateInterval, "u", 10, "seconds between updates (0 = don't update)")
	flag.Parse()
	if numBurn <= 0 {
		numBurn = runtime.NumCPU()
	}
}

func main() {
	runtime.GOMAXPROCS(numBurn)
	fmt.Printf("Burning %d CPUs/cores\n", numBurn)
	for i := 0; i < numBurn; i++ {
		go cpuBurn()
	}
	if updateInterval > 0 {
		t := time.Tick(time.Duration(updateInterval) * time.Second)
		for secs := updateInterval; ; secs += updateInterval {
			<-t
			fmt.Printf("%d seconds\n", secs)
		}
	} else {
		select {} // wait forever
	}
}

离线

#2 2019-11-08 08:11:23

晕哥
管理员
注册时间: 2017-09-06
已发帖子: 9,348
积分: 9202

Re: 燃烧吧cpu(go语言版cpuburn)

还有这种操作 ^_^





离线

页脚

工信部备案:粤ICP备20025096号 Powered by FluxBB

感谢为中文互联网持续输出优质内容的各位老铁们。 QQ: 516333132, 微信(wechat): whycan_cn (哇酷网/挖坑网/填坑网) service@whycan.cn