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

hash performance sha256 vs. sha512 #209

Open
ThomasWaldmann opened this issue Mar 1, 2015 · 7 comments
Open

hash performance sha256 vs. sha512 #209

ThomasWaldmann opened this issue Mar 1, 2015 · 7 comments

Comments

@ThomasWaldmann
Copy link
Contributor

I just learned that sha512 is faster than sha256 (on 64bit platforms, see benchmark below). attic uses sha256 at some places, could/should it be replaced by sha512?

Attic uses hmac-sha256. I did similar measurements for hmac-sha256 and -sha512 and the speed was as shown below.

$ python3.2 -m timeit -r 10 -s 'from hashlib import new; h = new("sha256"); x=b"foobar"*1000000' 'h.update(x)'
10 loops, best of 10: 29.2 msec per loop

$ python3.2 -m timeit -r 10 -s 'from hashlib import new; h = new("sha512"); x=b"foobar"*1000000' 'h.update(x)'
100 loops, best of 10: 18.6 msec per loop

@ThomasWaldmann
Copy link
Contributor Author

Some 32bit linux, py 2.7.6 values from a helpful guy on IRC:

$ python -m timeit -r 10 -s 'from hashlib import new; h = new("sha256"); x=b"foobar"_1000000' 'h.update(x)'
10 loops, best of 10: 41.5 msec per loop
$ python -m timeit -r 10 -s 'from hashlib import new; h = new("sha512"); x=b"foobar"_1000000' 'h.update(x)'
10 loops, best of 10: 43.9 msec per loop

Vendor ID: GenuineIntel
CPU family: 6
Model: 23
Stepping: 6
CPU MHz: 800.000

sha512 is just a little slower than sha256 there.

@ThomasWaldmann
Copy link
Contributor Author

Just for completeness: if anybody could post values from non-x86/amd64 platforms for 32 and/or 64bit, that would be helpful.

@ThomasWaldmann
Copy link
Contributor Author

Note: attic could use hmac-sha512 or hmac-sha512-256 (truncated to 256bits).
Both would be incompatible to old repositories, but with the latter, record layout would stay the same.

@ThomasWaldmann
Copy link
Contributor Author

@ThomasWaldmann
Copy link
Contributor Author

More data from helpful IRC guy:

Raspberry PI, Python 2.7.3, CPU: ARMv6-compatible processor rev 7 (v6l)

$ python -m timeit -r 10 -s 'from hashlib import new; h = new("sha256"); x=b"foobar"*1000000' 'h.update(x)'
10 loops, best of 10: 231 msec per loop

$ python -m timeit -r 10 -s 'from hashlib import new; h = new("sha512"); x=b"foobar"*1000000' 'h.update(x)'
10 loops, best of 10: 451 msec per loop

So, obviously we need BOTH sha256 and sha512, for best performance depending on the CPU architecture.

@ThomasWaldmann
Copy link
Contributor Author

see measurements in PR #207. as there are a lot of factors contributing to backup speed, the faster hash improved speed about 2-3% for me.

@tgharold
Copy link

tgharold commented Jul 2, 2015

AMD Phenom(tm) II X4 810 Processor (64bit CentOS 6)

SHA256 - 10 loops, best of 10: 36.5 msec per loop
SHA512 - 10 loops, best of 10: 22.6 msec per loop

AMD Opteron(tm) Processor 4180 (64bit CentOS 6)

SHA256 - 10 loops, best of 10: 36 msec per loop
SHA512 - 10 loops, best of 10: 23.3 msec per loop

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