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