2
2
import struct
3
3
import timeit
4
4
5
- import pandas as pd
6
5
import numpy as np
6
+ import pandas as pd
7
7
from numpy .random import RandomState
8
8
9
9
rs = RandomState ()
@@ -44,7 +44,7 @@ def run_timer(dist, command, numpy_command=None, setup='', random_type=''):
44
44
mod = 'randomstate.prng' if rng != 'random' else 'numpy'
45
45
key = '-' .join ((mod , rng , dist )).replace ('"' , '' )
46
46
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 ))
48
48
49
49
s = pd .Series (res )
50
50
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=''):
68
68
69
69
def timer_uniform ():
70
70
dist = 'random_sample'
71
- command = 'rs.{dist} (1000000)'
71
+ command = 'rs.random_sample (1000000)'
72
72
run_timer (dist , command , None , SETUP , 'Uniforms' )
73
73
74
74
75
75
def timer_32bit ():
76
76
info = np .iinfo (np .uint32 )
77
77
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' )
83
83
84
84
85
85
def timer_64bit ():
86
86
info = np .iinfo (np .uint64 )
87
87
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' )
93
93
94
94
95
95
def timer_normal ():
96
- command = 'rs.{dist}(1000000, method="bm")'
97
- command_numpy = 'rs.{dist}(1000000)'
98
96
dist = 'standard_normal'
97
+ command = 'rs.standard_normal(1000000, method="bm")'
98
+ command_numpy = 'rs.standard_normal(1000000)'
99
99
run_timer (dist , command , command_numpy , SETUP , 'Box-Muller normals' )
100
100
101
101
102
102
def timer_normal_zig ():
103
- command = 'rs.{dist}(1000000, method="zig")'
104
- command_numpy = 'rs.{dist}(1000000)'
105
103
dist = 'standard_normal'
104
+ command = 'rs.standard_normal(1000000, method="zig")'
105
+ command_numpy = 'rs.standard_normal(1000000)'
106
106
run_timer (dist , command , command_numpy , SETUP , 'Standard normals (Ziggurat)' )
107
107
108
108
0 commit comments