blob: 616391653cd57551894965e20879851d1b2d327a [file] [log] [blame]
Sybren A. Stüvel360d0422011-08-10 10:52:591#!/usr/bin/env python
Sybren A. Stüvel9d2cd9a2015-11-05 19:53:382# -*- coding: utf-8 -*-
Roy Kokkelkoren0659aac2015-10-25 15:12:113#
4# Copyright 2011 Sybren A. Stüvel <[email protected]>
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üvel3934ab42016-02-05 15:01:2010# https://www.apache.org/licenses/LICENSE-2.0
Roy Kokkelkoren0659aac2015-10-25 15:12:1111#
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üvel360d0422011-08-10 10:52:5917
18import time
19import rsa
20
21poolsize = 8
22accurate = True
23
Sybren A. Stüvel360d0422011-08-10 10:52:5924
Sybren A. Stüveld3d10342016-01-22 10:36:0625def run_speed_test(bitsize):
Sybren A. Stüvel360d0422011-08-10 10:52:5926 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üveld3d10342016-01-22 10:36:0638 print('%5i bit: %9.3f sec. (%i iterations over %.1f seconds)' %
39 (bitsize, dur_per_call, iterations, duration))
40
Sybren A. Stüvel360d0422011-08-10 10:52:5941
Sybren A. Stüvelf95dbb72016-01-22 11:19:0942if __name__ == '__main__':
43 for bitsize in (128, 256, 384, 512, 1024, 2048, 3072, 4096):
44 run_speed_test(bitsize)