Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
Roy Kokkelkoren | 0659aac | 2015-10-25 16:12:11 +0100 | [diff] [blame] | 2 | # Copyright 2011 Sybren A. Stüvel <sybren@stuvel.eu> |
| 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. |
| 6 | # You may obtain a copy of the License at |
| 7 | # |
Sybren A. Stüvel | 3934ab4 | 2016-02-05 16:01:20 +0100 | [diff] [blame] | 8 | # https://www.apache.org/licenses/LICENSE-2.0 |
Roy Kokkelkoren | 0659aac | 2015-10-25 16:12:11 +0100 | [diff] [blame] | 9 | # |
| 10 | # Unless required by applicable law or agreed to in writing, software |
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | # See the License for the specific language governing permissions and |
| 14 | # limitations under the License. |
Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 15 | |
| 16 | import time |
| 17 | import rsa |
| 18 | |
| 19 | poolsize = 8 |
| 20 | accurate = True |
| 21 | |
Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 22 | |
Sybren A. Stüvel | d3d1034 | 2016-01-22 11:36:06 +0100 | [diff] [blame] | 23 | def run_speed_test(bitsize): |
Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 24 | iterations = 0 |
| 25 | start = end = time.time() |
| 26 | |
| 27 | # At least a number of iterations, and at least 2 seconds |
| 28 | while iterations < 10 or end - start < 2: |
| 29 | iterations += 1 |
| 30 | rsa.newkeys(bitsize, accurate=accurate, poolsize=poolsize) |
| 31 | end = time.time() |
| 32 | |
| 33 | duration = end - start |
| 34 | dur_per_call = duration / iterations |
| 35 | |
Sybren A. Stüvel | d3d1034 | 2016-01-22 11:36:06 +0100 | [diff] [blame] | 36 | print('%5i bit: %9.3f sec. (%i iterations over %.1f seconds)' % |
| 37 | (bitsize, dur_per_call, iterations, duration)) |
| 38 | |
Sybren A. Stüvel | 360d042 | 2011-08-10 12:52:59 +0200 | [diff] [blame] | 39 | |
Sybren A. Stüvel | f95dbb7 | 2016-01-22 12:19:09 +0100 | [diff] [blame] | 40 | if __name__ == '__main__': |
| 41 | for bitsize in (128, 256, 384, 512, 1024, 2048, 3072, 4096): |
| 42 | run_speed_test(bitsize) |