@@ -54,14 +54,33 @@ def run(args):
54
54
num_samples ,
55
55
selected_holder_type ,
56
56
)
57
+ pflush ("sizeof_smart_holder:" , m .sizeof_smart_holder ())
58
+
59
+ def find_call_repetitions (
60
+ callable ,
61
+ time_delta_floor = 1.0e-6 ,
62
+ target_elapsed_secs_multiplier = 1.05 , # Empirical.
63
+ target_elapsed_secs_tolerance = 0.05 ,
64
+ max_iterations = 100 ,
65
+ ):
66
+ td_target = (
67
+ call_repetitions_target_elapsed_secs * target_elapsed_secs_multiplier
68
+ )
69
+ crd = call_repetitions_first_pass
70
+ for _ in range (max_iterations ):
71
+ td = callable (crd )
72
+ crd = max (1 , int (td_target * crd / max (td , time_delta_floor )))
73
+ if abs (td - td_target ) / td_target < target_elapsed_secs_tolerance :
74
+ return crd
75
+ raise RuntimeError ("find_call_repetitions failure: max_iterations exceeded." )
57
76
58
77
for size_exponent in range (
59
78
size_exponent_min , size_exponent_max + 1 , size_exponent_step
60
79
):
61
80
data_size = 2 ** size_exponent
62
81
pflush (data_size , "data_size" )
63
82
ratios = collections .defaultdict (list )
64
- call_repetitions_dynamic = None
83
+ call_repetitions = None
65
84
for _ in range (num_samples ):
66
85
row_0 = None
67
86
for nb_label , nb_type in [
@@ -77,32 +96,27 @@ def run(args):
77
96
continue
78
97
nb1 = nb_type (data_size )
79
98
nb2 = nb_type (data_size )
80
- if call_repetitions_dynamic is None :
99
+
100
+ def many_sum (call_repetitions ):
81
101
assert int (round (nb1 .sum ())) == data_size
82
102
t0 = time .time ()
83
- for _ in range (call_repetitions_first_pass ):
103
+ for _ in range (call_repetitions ):
84
104
nb1 .sum ()
85
- td_sum = time .time () - t0
86
- call_repetitions_dynamic = max (
87
- call_repetitions_first_pass ,
88
- int (
89
- call_repetitions_target_elapsed_secs
90
- * call_repetitions_first_pass
91
- / max (td_sum , 1.0e-6 )
92
- )
93
- + 1 ,
94
- )
95
- pflush (call_repetitions_dynamic , "call_repetitions_dynamic" )
96
- assert int (round (nb1 .sum ())) == data_size
97
- t0 = time .time ()
98
- for _ in range (call_repetitions_dynamic ):
99
- nb1 .sum ()
100
- td_sum = time .time () - t0
101
- assert nb1 .add (nb2 ) == data_size
102
- t0 = time .time ()
103
- for _ in range (call_repetitions_dynamic ):
104
- nb1 .add (nb2 )
105
- td_add = time .time () - t0
105
+ return time .time () - t0
106
+
107
+ def many_add (call_repetitions ):
108
+ assert nb1 .add (nb2 ) == data_size
109
+ t0 = time .time ()
110
+ for _ in range (call_repetitions ):
111
+ nb1 .add (nb2 )
112
+ return time .time () - t0
113
+
114
+ if call_repetitions is None :
115
+ call_repetitions = find_call_repetitions (many_sum )
116
+ pflush (call_repetitions , "call_repetitions" )
117
+
118
+ td_sum = many_sum (call_repetitions )
119
+ td_add = many_add (call_repetitions )
106
120
row = [td_sum , td_add ]
107
121
if row_0 is None :
108
122
pflush (" Sum Add ratS ratA" )
0 commit comments