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