Skip to content

Commit b3e245f

Browse files
committed
Added slots
1 parent 91c3c86 commit b3e245f

5 files changed

Lines changed: 491 additions & 10 deletions

File tree

QuantileFlow/ddsketch/mapping/logarithmic.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
from .base import MappingScheme
55

66
class LogarithmicMapping(MappingScheme):
7-
def __init__(self, relative_accuracy: float):
7+
__slots__ = ('relative_accuracy', 'gamma', 'multiplier')
8+
9+
def __init__(self, relative_accuracy: float):
810
self.relative_accuracy = relative_accuracy
911
self.gamma = (1 + relative_accuracy) / (1 - relative_accuracy)
1012
self.multiplier = 1 / math.log(self.gamma)

QuantileFlow/ddsketch/storage/contiguous.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ class ContiguousStorage(Storage):
1515
- If inserting below min: collapse if range too large, otherwise adjust min
1616
- If inserting above max: collapse lowest buckets to make room
1717
"""
18+
19+
__slots__ = ('total_count', 'counts', 'min_index', 'max_index',
20+
'num_buckets', 'arr_index_of_min_bucket', 'collapse_count',
21+
'max_buckets', 'bucket_mask', 'strategy')
1822

1923
def __init__(self, max_buckets: int = 2048):
2024
"""

benchmarks/6add_slots.json

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"timestamp": "2026-01-10T16:42:43.578971",
3+
"name": "6add_slots",
4+
"metadata": {
5+
"num_values": 10000000,
6+
"num_trials": 5,
7+
"timestamp": "2026-01-10T16:42:43.578962"
8+
},
9+
"stats": [
10+
{
11+
"function": "profile_ddsketch.py:17(run_sketch_operations)",
12+
"ncalls": 1,
13+
"tottime": 1.33988225,
14+
"cumtime": 11.5264426936,
15+
"percall_tot": 1.33988225,
16+
"percall_cum": 11.5264426936
17+
},
18+
{
19+
"function": "core.py:77(insert)",
20+
"ncalls": 10000000,
21+
"tottime": 3.3348853683999997,
22+
"cumtime": 10.185277087,
23+
"percall_tot": 3.3348853684e-07,
24+
"percall_cum": 1.0185277087e-06
25+
},
26+
{
27+
"function": "contiguous.py:42(add)",
28+
"ncalls": 10000000,
29+
"tottime": 3.8266771040000003,
30+
"cumtime": 3.8266771040000003,
31+
"percall_tot": 3.826677104e-07,
32+
"percall_cum": 3.826677104e-07
33+
},
34+
{
35+
"function": "logarithmic.py:14(compute_bucket_index)",
36+
"ncalls": 10000000,
37+
"tottime": 1.7708338908,
38+
"cumtime": 3.0237146146000002,
39+
"percall_tot": 1.7708338908000002e-07,
40+
"percall_cum": 3.0237146146e-07
41+
},
42+
{
43+
"function": "~:0(<built-in method math.log>)",
44+
"ncalls": 10000001,
45+
"tottime": 0.6956715138,
46+
"cumtime": 0.6956715138,
47+
"percall_tot": 6.956714442328556e-08,
48+
"percall_cum": 6.956714442328556e-08
49+
},
50+
{
51+
"function": "~:0(<built-in method math.ceil>)",
52+
"ncalls": 10000000,
53+
"tottime": 0.5572106932,
54+
"cumtime": 0.5572106932,
55+
"percall_tot": 5.572106932e-08,
56+
"percall_cum": 5.572106932e-08
57+
},
58+
{
59+
"function": "core.py:128(quantile)",
60+
"ncalls": 4,
61+
"tottime": 0.000548316,
62+
"cumtime": 0.0012531198,
63+
"percall_tot": 0.000137079,
64+
"percall_cum": 0.00031327995
65+
},
66+
{
67+
"function": "contiguous.py:172(get_count)",
68+
"ncalls": 3324,
69+
"tottime": 0.0006952066000000001,
70+
"cumtime": 0.0006952066000000001,
71+
"percall_tot": 2.092879594892521e-07,
72+
"percall_cum": 2.092879594892521e-07
73+
},
74+
{
75+
"function": "core.py:24(__init__)",
76+
"ncalls": 1,
77+
"tottime": 5.0892e-06,
78+
"cumtime": 3.0236799999999995e-05,
79+
"percall_tot": 5.0892e-06,
80+
"percall_cum": 3.0236799999999995e-05
81+
},
82+
{
83+
"function": "~:0(<method 'disable' of '_lsprof.Profiler' objects>)",
84+
"ncalls": 1,
85+
"tottime": 2.64168e-05,
86+
"cumtime": 2.64168e-05,
87+
"percall_tot": 2.64168e-05,
88+
"percall_cum": 2.64168e-05
89+
},
90+
{
91+
"function": "contiguous.py:23(__init__)",
92+
"ncalls": 2,
93+
"tottime": 7.3314e-06,
94+
"cumtime": 2.0227400000000002e-05,
95+
"percall_tot": 3.6657e-06,
96+
"percall_cum": 1.0113700000000001e-05
97+
},
98+
{
99+
"function": "~:0(<built-in method numpy.zeros>)",
100+
"ncalls": 2,
101+
"tottime": 1.0474e-05,
102+
"cumtime": 1.0474e-05,
103+
"percall_tot": 5.237e-06,
104+
"percall_cum": 5.237e-06
105+
},
106+
{
107+
"function": "logarithmic.py:18(compute_value_from_index)",
108+
"ncalls": 4,
109+
"tottime": 7.9294e-06,
110+
"cumtime": 9.5972e-06,
111+
"percall_tot": 1.98235e-06,
112+
"percall_cum": 2.3993e-06
113+
},
114+
{
115+
"function": "logarithmic.py:9(__init__)",
116+
"ncalls": 1,
117+
"tottime": 3.4370000000000003e-06,
118+
"cumtime": 4.9202e-06,
119+
"percall_tot": 3.4370000000000003e-06,
120+
"percall_cum": 4.9202e-06
121+
},
122+
{
123+
"function": "base.py:17(__init__)",
124+
"ncalls": 2,
125+
"tottime": 2.422e-06,
126+
"cumtime": 2.422e-06,
127+
"percall_tot": 1.211e-06,
128+
"percall_cum": 1.211e-06
129+
},
130+
{
131+
"function": "~:0(<built-in method math.pow>)",
132+
"ncalls": 4,
133+
"tottime": 1.6678000000000002e-06,
134+
"cumtime": 1.6678000000000002e-06,
135+
"percall_tot": 4.1695000000000004e-07,
136+
"percall_cum": 4.1695000000000004e-07
137+
}
138+
]
139+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"timestamp": "2026-01-10T17:13:13.833726",
3+
"name": "7reword_value_comparisons",
4+
"metadata": {
5+
"num_values": 10000000,
6+
"num_trials": 5,
7+
"timestamp": "2026-01-10T17:13:13.833712"
8+
},
9+
"stats": [
10+
{
11+
"function": "profile_ddsketch.py:26(run_sketch_operations)",
12+
"ncalls": 1,
13+
"tottime": 1.8573772013999998,
14+
"cumtime": 15.3256251814,
15+
"percall_tot": 1.8573772013999998,
16+
"percall_cum": 15.3256251814
17+
},
18+
{
19+
"function": "core.py:77(insert)",
20+
"ncalls": 10000000,
21+
"tottime": 4.248560426,
22+
"cumtime": 13.4664414144,
23+
"percall_tot": 4.2485604260000007e-07,
24+
"percall_cum": 1.34664414144e-06
25+
},
26+
{
27+
"function": "contiguous.py:42(add)",
28+
"ncalls": 10000000,
29+
"tottime": 5.1584048128,
30+
"cumtime": 5.1584048128,
31+
"percall_tot": 5.158404812800001e-07,
32+
"percall_cum": 5.158404812800001e-07
33+
},
34+
{
35+
"function": "logarithmic.py:14(compute_bucket_index)",
36+
"ncalls": 10000000,
37+
"tottime": 2.3456515052,
38+
"cumtime": 4.0594761756,
39+
"percall_tot": 2.3456515052000006e-07,
40+
"percall_cum": 4.0594761756000005e-07
41+
},
42+
{
43+
"function": "~:0(<built-in method math.log>)",
44+
"ncalls": 10000001,
45+
"tottime": 0.9696837526,
46+
"cumtime": 0.9696837526,
47+
"percall_tot": 9.696836556316345e-08,
48+
"percall_cum": 9.696836556316345e-08
49+
},
50+
{
51+
"function": "~:0(<built-in method math.ceil>)",
52+
"ncalls": 10000000,
53+
"tottime": 0.7441432736,
54+
"cumtime": 0.7441432736,
55+
"percall_tot": 7.441432736e-08,
56+
"percall_cum": 7.441432736e-08
57+
},
58+
{
59+
"function": "core.py:129(quantile)",
60+
"ncalls": 4,
61+
"tottime": 0.0007785592000000001,
62+
"cumtime": 0.0017527554,
63+
"percall_tot": 0.00019463980000000003,
64+
"percall_cum": 0.00043818885
65+
},
66+
{
67+
"function": "contiguous.py:172(get_count)",
68+
"ncalls": 3338,
69+
"tottime": 0.0009408718,
70+
"cumtime": 0.0009408718,
71+
"percall_tot": 2.7929728771085877e-07,
72+
"percall_cum": 2.7929728771085877e-07
73+
},
74+
{
75+
"function": "core.py:24(__init__)",
76+
"ncalls": 1,
77+
"tottime": 1.0402600000000001e-05,
78+
"cumtime": 5.38102e-05,
79+
"percall_tot": 1.0402600000000001e-05,
80+
"percall_cum": 5.38102e-05
81+
},
82+
{
83+
"function": "~:0(<method 'disable' of '_lsprof.Profiler' objects>)",
84+
"ncalls": 1,
85+
"tottime": 4.279240000000001e-05,
86+
"cumtime": 4.279240000000001e-05,
87+
"percall_tot": 4.279240000000001e-05,
88+
"percall_cum": 4.279240000000001e-05
89+
},
90+
{
91+
"function": "contiguous.py:23(__init__)",
92+
"ncalls": 2,
93+
"tottime": 1.21986e-05,
94+
"cumtime": 3.51634e-05,
95+
"percall_tot": 6.0993e-06,
96+
"percall_cum": 1.75817e-05
97+
},
98+
{
99+
"function": "logarithmic.py:18(compute_value_from_index)",
100+
"ncalls": 4,
101+
"tottime": 2.9578800000000002e-05,
102+
"cumtime": 3.332440000000001e-05,
103+
"percall_tot": 7.3947000000000005e-06,
104+
"percall_cum": 8.331100000000002e-06
105+
},
106+
{
107+
"function": "~:0(<built-in method numpy.zeros>)",
108+
"ncalls": 2,
109+
"tottime": 1.8467600000000003e-05,
110+
"cumtime": 1.8467600000000003e-05,
111+
"percall_tot": 9.233800000000001e-06,
112+
"percall_cum": 9.233800000000001e-06
113+
},
114+
{
115+
"function": "logarithmic.py:9(__init__)",
116+
"ncalls": 1,
117+
"tottime": 5.8884e-06,
118+
"cumtime": 8.244200000000001e-06,
119+
"percall_tot": 5.8884e-06,
120+
"percall_cum": 8.244200000000001e-06
121+
},
122+
{
123+
"function": "base.py:17(__init__)",
124+
"ncalls": 2,
125+
"tottime": 4.4972e-06,
126+
"cumtime": 4.4972e-06,
127+
"percall_tot": 2.2486e-06,
128+
"percall_cum": 2.2486e-06
129+
},
130+
{
131+
"function": "~:0(<built-in method math.pow>)",
132+
"ncalls": 4,
133+
"tottime": 3.7456e-06,
134+
"cumtime": 3.7456e-06,
135+
"percall_tot": 9.364e-07,
136+
"percall_cum": 9.364e-07
137+
}
138+
]
139+
}

0 commit comments

Comments
 (0)