Performance testing suite

This commit is contained in:
Mauricio Gomes 2018-05-30 10:11:26 -04:00
parent a12c80a662
commit cafc082102
2 changed files with 99 additions and 4 deletions

View file

@ -4,19 +4,19 @@ BLAKE2 is a cryptographic hash function faster than MD5, SHA-1, SHA-2, and SHA-3
More info at: [https://blake2.net](https://blake2.net). More info at: [https://blake2.net](https://blake2.net).
## SUMMARY ## Summary
This gem is a C-extension to enable using BLAKE2b in Ruby. This BLAKE2b implementation (or just BLAKE2) is optimized for 64-bit platforms with SSE support (excluding NEON-enabled ARMs). It produces digests of any size between 1 and 64 bytes. This gem is a C-extension to enable using BLAKE2b in Ruby. This BLAKE2b implementation (or just BLAKE2) is optimized for 64-bit platforms with SSE support (excluding NEON-enabled ARMs). It produces digests of any size between 1 and 64 bytes.
The C code for this gem is taken from the [official reference C implementation](https://github.com/BLAKE2/BLAKE2) as of commit [ca4c89314abff54e3806b44e4a08164f8204f09a](https://github.com/BLAKE2/BLAKE2/tree/ca4c89314abff54e3806b44e4a08164f8204f09a). The C code for this gem is taken from the [official reference C implementation](https://github.com/BLAKE2/BLAKE2) as of commit [ca4c89314abff54e3806b44e4a08164f8204f09a](https://github.com/BLAKE2/BLAKE2/tree/ca4c89314abff54e3806b44e4a08164f8204f09a).
## INSTALL ## Install
``` ```
gem install blake2b gem install blake2b
``` ```
## USAGE ## Usage
``` ruby ``` ruby
require 'blake2b' require 'blake2b'
@ -60,7 +60,41 @@ Blake2b.bytes(input, key, out_len)
``` ```
## DEVELOPMENT ## Performance
`Blake2b` really shines on larger inputs. Here are some benchmarks on various input sizes. You can find the performance suite used for these benchmarks at `performance/performance_suite.rb`. All tests were run on an iMac 27" Late 2014, 4GHz Core i7 CPU (4790K) w/ SSE4.1 + SSE4.2, 32GB DDR3 RAM.
### 1KB (1M digests)
```
MD5 result: 2.694545999998809 seconds.
SHA2 result: 4.037195000011707 seconds.
SHA512 result: 3.213850000000093 seconds.
BLAKE2s result: 5.6867979999951785 seconds.
BLAKE2b result: 4.375018999999156 seconds.
```
### 50KB (500k digests)
```
MD5 result: 34.33997299999464 seconds.
SHA2 result: 50.161426999999094 seconds.
SHA512 result: 35.24845699999423 seconds.
BLAKE2s result: 64.8592859999917 seconds.
BLAKE2b result: 30.783814999987953 seconds.
```
### 250KB (500k digests)
```
MD5 result: 67.89016799999808 seconds.
SHA2 result: 103.09026799999992 seconds.
SHA512 result: 72.46762200001103 seconds.
BLAKE2s result: 133.5229810000019 seconds.
BLAKE2b result: 64.30263599999307 seconds.
```
## Development
After checking out the repo, run `bundle` to install dependencies. Then, After checking out the repo, run `bundle` to install dependencies. Then,
run `rake full` to build and test, or `rake test` to only run the tests. run `rake full` to build and test, or `rake test` to only run the tests.

View file

@ -0,0 +1,61 @@
require 'digest'
require 'blake2'
require 'blake2b'
sample_string = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec quis fermentum mauris, laoreet ultricies ipsum. Phasellus iaculis lacinia bibendum. Aenean eu lectus vitae nisi pellentesque condimentum. Cras imperdiet risus ut interdum dignissim. Nam ultricies vulputate varius. Morbi vehicula mi sit amet velit cursus, eu blandit dolor venenatis. Nunc vitae varius leo. Mauris metus nibh, ultrices nec odio in, viverra luctus purus. Duis luctus, dolor vel sodales semper, enim mauris sagittis dolor, at vehicula ligula ante eu lorem. Morbi porttitor lorem id turpis facilisis volutpat. Sed elementum porttitor sem, a ornare ligula. Integer tincidunt aliquam suscipit. Sed aliquam ligula id enim fringilla, vel ornare ante bibendum. Integer tincidunt, augue id condimentum fermentum, dolor urna molestie massa, sed congue enim quam eget arcu. Quisque feugiat purus sit amet porttitor tincidunt.
Fusce odio libero, lobortis quis ornare sit amet, dignissim sed erat. Praesent a iaculis ex. Ut libero amet."
run_count = 500_000
### MD5
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
run_count.times do |i|
Digest::MD5.hexdigest("#{i}#{sample_string}")
end
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
puts "MD5 result: #{ending - starting} seconds."
### SHA2
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
run_count.times do |i|
Digest::SHA2.hexdigest("#{i}#{sample_string}")
end
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
puts "SHA2 result: #{ending - starting} seconds."
### SHA512
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
run_count.times do |i|
Digest::SHA512.hexdigest("#{i}#{sample_string}")
end
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
puts "SHA512 result: #{ending - starting} seconds."
### BLAKE2s
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
unkeyed = Blake2::Key.none
run_count.times do |i|
Blake2.new(32, unkeyed).digest("#{i}#{sample_string}", :to_hex)
end
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
puts "BLAKE2s result: #{ending - starting} seconds."
### BLAKE2b
starting = Process.clock_gettime(Process::CLOCK_MONOTONIC)
unkeyed = Blake2b::Key.none
run_count.times do |i|
Blake2b.new(32, unkeyed).digest("#{i}#{sample_string}", :to_hex)
end
ending = Process.clock_gettime(Process::CLOCK_MONOTONIC)
puts "BLAKE2b result: #{ending - starting} seconds."