1 Star 0 Fork 1

John / go-web-framework-benchmark

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
pow.go 466 Bytes
一键复制 编辑 原始数据 按行查看 历史
鸟窝 提交于 2019-01-05 23:53 . add cpu-bound test
package main
import (
"crypto/sha256"
"math/big"
"runtime"
"strconv"
)
func pow(targetBits int) {
target := big.NewInt(1)
target.Lsh(target, uint(256-targetBits))
var hashInt big.Int
var hash [32]byte
nonce := 0
for {
data := "hello world " + strconv.Itoa(nonce)
hash = sha256.Sum256([]byte(data))
hashInt.SetBytes(hash[:])
if hashInt.Cmp(target) == -1 {
break
} else {
nonce++
}
if nonce%100 == 0 {
runtime.Gosched()
}
}
}
1
https://gitee.com/johng/go-web-framework-benchmark.git
git@gitee.com:johng/go-web-framework-benchmark.git
johng
go-web-framework-benchmark
go-web-framework-benchmark
master

搜索帮助