Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (go env)?
go env Output
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04.6 LTS
and my cpu is Intel(R) Xeon(R) E5-2690 v3 @ 2.60GHz(support avx2)
openssl version is OpenSSL 1.0.2g 1 Mar 2016
What did you do?
I test the performance in the following three cases:
Call the openssl library with C
Call the crypto library with Go
Call the openssl library with Go's Cgo
For different length strings, do 10,000,000 sha256 calculations.
The result is as follows, the unit of data is second.
length of string
What did you expect to see?
Test results in different cases are similar.
What did you see instead?
It can be seen that when the length of the string is small, openssl is more than 30% faster than golang.
When string length is long, using cgo to call openssl is also 10% faster than golang.
Here is my demo (does not contain loops and time statistics), please indicate if there is an error, thank you.
Call the openssl library with C (need to install openssl-dev)
So can we optimize the sha256 of golang? Because this is a hot function in my application, I am concerned about the time efficiency of sha256.
Here are some preliminary analysis, I hope it can provide some help.
The longest running function in the test, in golang is $GOROOT/src/crypto/sha256/sha256block_amd64.sblockavx2 case,
in openssl is sha256_block_data_order_avx2.
You can download openssl 1.0.2g source file, make , then can found it in openssl-1.0.2g/crypto/sha/sha256-x86_64.s. sha256-x86_64.s.zip
Since I am not very familiar with assembly, I don't know how to optimize.
Look forward to your reply, thank you.
The text was updated successfully, but these errors were encountered:
The Go standard library places higher value on reducing complexity, so it doesn't aim to be the fastest at implementing primitives. If this makes it unsuitable for your use case, please do share some details, as we take that into account when deciding how much complexity to take. See also https://golang.org/design/cryptography-principles.