Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bench test with golang std ed25519 #200

Open
giskook opened this issue May 29, 2022 · 3 comments
Open

bench test with golang std ed25519 #200

giskook opened this issue May 29, 2022 · 3 comments

Comments

@giskook
Copy link

giskook commented May 29, 2022

hi,
I want to use the project to my go project.
1. I wrappered the project with rust lib and generate a C header.
2. make a project to test the perfermance.

I got the result.

goos: darwin
goarch: arm64
pkg: github.com/giskook/ed25519_bench
BenchmarkStdEd25519NewKey-10    	   61866	     17676 ns/op
BenchmarkNewKey-10              	   95047	     12670 ns/op
BenchmarkStdEd25519Sign-10      	   51584	     23155 ns/op
BenchmarkSign-10                	   70915	     16794 ns/op
BenchmarkStdEd25519Verify-10    	   23914	     50102 ns/op
BenchmarkVerify-10              	   32502	     36692 ns/op
PASS
ok  	github.com/giskook/ed25519_bench	9.527s

and

goos: linux
goarch: amd64
pkg: github.com/giskook/ed25519_bench
cpu: Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
BenchmarkStdEd25519NewKey-16    	   58395	     20548 ns/op
BenchmarkNewKey-16              	   66391	     18012 ns/op
BenchmarkStdEd25519Sign-16      	   47431	     25199 ns/op
BenchmarkSign-16                	   51754	     23096 ns/op
BenchmarkStdEd25519Verify-16    	   19858	     60420 ns/op
BenchmarkVerify-16              	   22867	     52159 ns/op
PASS
ok  	github.com/giskook/ed25519_bench	9.211s

It seems the perfermance is not outstanding. Am I missing something?

my test project: https://github.com/giskook/ed25519_bench

@tarcieri
Copy link
Contributor

tarcieri commented May 29, 2022

CGo has high overhead compared to the time it takes to actually perform the cryptographic operations.

See the “Why not cgo” section of this blog post:

https://words.filippo.io/rustgo/

@giskook
Copy link
Author

giskook commented May 29, 2022

I had add a empty CGO call to my test project.It shows the cgo call only has lower overhead.you can review my project.

the empty CGO call takes ~25ns on my laptap, ~50ns on my aws machine. the real work takes about 12611ns.

the cgo call only takes about 0.2% time costs.

the result:

goos: darwin
goarch: arm64
pkg: github.com/giskook/ed25519_bench
BenchmarkStdEd25519NewKey-10           	   62973	     17480 ns/op
BenchmarkNewKey-10                     	   94894	     12611 ns/op
BenchmarkStdEd25519Sign-10             	   51811	     23087 ns/op
BenchmarkSign-10                       	   70196	     16753 ns/op
BenchmarkStdEd25519Verify-10           	   23860	     50249 ns/op
BenchmarkVerify-10                     	   32156	     37192 ns/op
BenchmarkJustTestForCGoEmptyCall-10    	45658698	        24.94 ns/op
PASS
ok  	github.com/giskook/ed25519_bench	11.610s

and

goos: linux
goarch: amd64
pkg: github.com/giskook/ed25519_bench
cpu: Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz
BenchmarkStdEd25519NewKey-16           	   58423	     20544 ns/op
BenchmarkNewKey-16                     	   66846	     18314 ns/op
BenchmarkStdEd25519Sign-16             	   47661	     25183 ns/op
BenchmarkSign-16                       	   51940	     23089 ns/op
BenchmarkStdEd25519Verify-16           	   19798	     60634 ns/op
BenchmarkVerify-16                     	   22994	     51869 ns/op
BenchmarkJustTestForCGoEmptyCall-16    	23624349	        50.83 ns/op
PASS
ok  	github.com/giskook/ed25519_bench	10.498s

@giskook
Copy link
Author

giskook commented May 30, 2022

hi, I run a the test between go crypto/ed25519(without cgo) vs ed25519-dalek:

test Method:
for go(version 1.18.2), go to the go src code, run the bench:

go test -bench .

for ed25519-dalek(1.0.1) run:

cargo bench --features="batch"

the result:

case 1

env:

go version chip OS mem Total CPU numbers
1.18.2 m1 macOS 32G 10
reuslt:
  sign verify
go crypto/ed25519 22941 ns 50217 ns
ed25519-dalek 12868 ns 31581 ns

ed25519-dalek's sign performance improvement: 43.91%;

ed25519-dalek's verify performance improvement: 37.11%;

case 2

env:

go version chip OS mem Total CPU Numbers
1.18.2 Intel(R) Xeon(R) Platinum 8375C CPU @ 2.90GHz Ubuntu 64G 16

reusult:

  sign verify
go crypto/ed25519 25200 ns 60571 ns
ed25519-dalek 18480 ns 46782 ns

ed25519-dalek's sign performance improvement: 26.67%;

ed25519-dalek's verify performance improvement: 22.77%;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants