blob: d2f4b2de44771a81985af0ba7a84184ae7573b63 [file] [log] [blame]
Sybren A. Stüvel360d0422011-08-10 12:52:59 +02001#!/usr/bin/env python
Roy Kokkelkoren0659aac2015-10-25 16:12:11 +01002#
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üvel360d0422011-08-10 12:52:59 +020016
17import time
18import rsa
19
20poolsize = 8
21accurate = True
22
23def 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
40for bitsize in (128, 256, 384, 512, 1024, 2048, 3072, 4096):
41 run_speed_test(bitsize)
42
43