bcrypt的cost值测试耗时结果

package main

import (
	"log"
	"time"

	"golang.org/x/crypto/bcrypt"
)
func main() {
	password := "secret"
	for cost := 10; cost < 20; cost++ {
		start := time.Now()
		hashPwd(password, cost)
		log.Println("cost =", cost, " 耗时:", time.Since(start))
	}
}

// 加密
func hashPwd(password string, cost int) (string, error) {
	hash, err := bcrypt.GenerateFromPassword([]byte(password), cost)
	return string(hash), err
}

结果如下:

2023/04/18 16:55:22 cost = 10  耗时: 73.259042ms
2023/04/18 16:55:23 cost = 11  耗时: 144.186666ms
2023/04/18 16:55:23 cost = 12  耗时: 296.26375ms
2023/04/18 16:55:23 cost = 13  耗时: 609.700625ms
2023/04/18 16:55:25 cost = 14  耗时: 1.207150375s
2023/04/18 16:55:27 cost = 15  耗时: 2.39822525s
2023/04/18 16:55:32 cost = 16  耗时: 4.847635708s
2023/04/18 16:55:42 cost = 17  耗时: 9.725984375s
2023/04/18 16:56:01 cost = 18  耗时: 19.40903275s
2023/04/18 16:56:40 cost = 19  耗时: 38.541072833s
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值