22import struct
33import timeit
44
5- import pandas as pd
65import numpy as np
6+ import pandas as pd
77from numpy .random import RandomState
88
99rs = RandomState ()
@@ -44,7 +44,7 @@ def run_timer(dist, command, numpy_command=None, setup='', random_type=''):
4444 mod = 'randomstate.prng' if rng != 'random' else 'numpy'
4545 key = '-' .join ((mod , rng , dist )).replace ('"' , '' )
4646 command = numpy_command if 'numpy' in mod else command
47- res [key ] = timer (command . format ( dist = dist ) , setup = setup .format (mod = mod , rng = rng ))
47+ res [key ] = timer (command , setup = setup .format (mod = mod , rng = rng ))
4848
4949 s = pd .Series (res )
5050 t = s .apply (lambda x : '{0:0.2f} ms' .format (x ))
@@ -68,41 +68,41 @@ def run_timer(dist, command, numpy_command=None, setup='', random_type=''):
6868
6969def timer_uniform ():
7070 dist = 'random_sample'
71- command = 'rs.{dist} (1000000)'
71+ command = 'rs.random_sample (1000000)'
7272 run_timer (dist , command , None , SETUP , 'Uniforms' )
7373
7474
7575def timer_32bit ():
7676 info = np .iinfo (np .uint32 )
7777 min , max = info .min , info .max
78- dist = 'randint '
79- command = 'rs.{dist}({min}, {max}+1, 1000000, dtype=np.uint64 )'
80- command = command . format ( dist = '{dist}' , min = min , max = max )
81- command_numpy = command
82- run_timer (dist , command , None , SETUP , '32-bit unsigned integers' )
78+ dist = 'random_uintegers '
79+ command = 'rs.random_uintegers( 1000000, 32 )'
80+ command_numpy = 'rs.randint({min}, {max}+1, 1000000, dtype=np.uint32)'
81+ command_numpy = command_numpy . format ( min = min , max = max )
82+ run_timer (dist , command , command_numpy , SETUP , '32-bit unsigned integers' )
8383
8484
8585def timer_64bit ():
8686 info = np .iinfo (np .uint64 )
8787 min , max = info .min , info .max
88- dist = 'randint '
89- command = 'rs.{dist}({min}, {max}+1, 1000000, dtype=np.uint64 )'
90- command = command . format ( dist = '{dist}' , min = min , max = max )
91- command_numpy = command
92- run_timer (dist , command , None , SETUP , '64-bit unsigned integers' )
88+ dist = 'random_uintegers '
89+ command = 'rs.random_uintegers( 1000000)'
90+ command_numpy = 'rs.randint({min}, {max}+1, 1000000, dtype=np.uint64)'
91+ command_numpy = command_numpy . format ( min = min , max = max )
92+ run_timer (dist , command , command_numpy , SETUP , '64-bit unsigned integers' )
9393
9494
9595def timer_normal ():
96- command = 'rs.{dist}(1000000, method="bm")'
97- command_numpy = 'rs.{dist}(1000000)'
9896 dist = 'standard_normal'
97+ command = 'rs.standard_normal(1000000, method="bm")'
98+ command_numpy = 'rs.standard_normal(1000000)'
9999 run_timer (dist , command , command_numpy , SETUP , 'Box-Muller normals' )
100100
101101
102102def timer_normal_zig ():
103- command = 'rs.{dist}(1000000, method="zig")'
104- command_numpy = 'rs.{dist}(1000000)'
105103 dist = 'standard_normal'
104+ command = 'rs.standard_normal(1000000, method="zig")'
105+ command_numpy = 'rs.standard_normal(1000000)'
106106 run_timer (dist , command , command_numpy , SETUP , 'Standard normals (Ziggurat)' )
107107
108108
0 commit comments