Skip to content

Commit e8fdfa4

Browse files
committed
Line Profile
1 parent 78140f9 commit e8fdfa4

2 files changed

Lines changed: 33 additions & 33 deletions

File tree

QuantileFlow/ddsketch/storage/contiguous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import math
88
import warnings
9-
from .base import Storage, BucketManagementStrategy
9+
from .base import Storage
1010

1111

1212
# Chunk size for dynamic growth (matches Datadog's default)

metrics-streaming-service/line_profile_kafka.txt

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
Line-by-Line Profiling Results - Kafka Metrics Streaming Benchmark
44
========================================================================================================================
55
Sketch Algorithm: QuantileFlow DDSketch
6-
Messages Processed: 18,200
7-
Total Runtime: 35.21 seconds
8-
Timestamp: 2026-01-21T21:56:36.388354
6+
Messages Processed: 872,161
7+
Total Runtime: 2091.55 seconds
8+
Timestamp: 2026-01-21T22:31:52.067860
99
========================================================================================================================
1010

1111
Timer unit: 1e-09 s
1212

13-
Total time: 0.307256 s
13+
Total time: 15.3584 s
1414
File: /home/taira/Code/QuantileFlow/QuantileFlow/ddsketch/core.py
1515
Function: DDSketch.insert at line 88
1616

@@ -27,25 +27,25 @@ Line # Hits Time Per Hit % Time Line Contents
2727
96 Raises:
2828
97 ValueError: If value is negative and cont_neg is False.
2929
98 """
30-
99 18200 20550382.0 1129.1 6.7 if value > 0:
31-
100 18047 233515222.0 12939.3 76.0 self.positive_store.add(self.mapping.compute_bucket_index(value), weight)
32-
101 153 118150.0 772.2 0.0 elif value < 0:
30+
99 872161 816360452.0 936.0 5.3 if value > 0:
31+
100 867922 1.17e+10 13455.3 76.0 self.positive_store.add(self.mapping.compute_bucket_index(value), weight)
32+
101 4239 3014973.0 711.2 0.0 elif value < 0:
3333
102 if self.cont_neg:
3434
103 self.negative_store.add(self.mapping.compute_bucket_index(-value), weight)
3535
104 else:
3636
105 raise ValueError("Negative values not supported when cont_neg is False")
3737
106 else:
38-
107 153 151963.0 993.2 0.0 self.zero_count += weight
38+
107 4239 3109202.0 733.5 0.0 self.zero_count += weight
3939
108
4040
109 # Track summary stats
41-
110 18200 9656253.0 530.6 3.1 self.count += weight
42-
111 18200 15514832.0 852.5 5.0 self._sum += value * weight
43-
112 18200 8611432.0 473.2 2.8 if value < self._min:
44-
113 4 2486.0 621.5 0.0 self._min = value
45-
114 18200 19123754.0 1050.8 6.2 if value > self._max:
46-
115 9 11482.0 1275.8 0.0 self._max = value
41+
110 872161 348912595.0 400.1 2.3 self.count += weight
42+
111 872161 1080794776.0 1239.2 7.0 self._sum += value * weight
43+
112 872161 489626681.0 561.4 3.2 if value < self._min:
44+
113 9 2982.0 331.3 0.0 self._min = value
45+
114 872161 938384938.0 1075.9 6.1 if value > self._max:
46+
115 9 6437.0 715.2 0.0 self._max = value
4747

48-
Total time: 25.1338 s
48+
Total time: 1404.78 s
4949
File: /home/taira/Code/QuantileFlow/QuantileFlow/ddsketch/core.py
5050
Function: DDSketch.quantile at line 152
5151

@@ -64,31 +64,31 @@ Line # Hits Time Per Hit % Time Line Contents
6464
162 Raises:
6565
163 ValueError: If q is not between 0 and 1 or if the sketch is empty.
6666
164 """
67-
165 54600 47049722.0 861.7 0.2 if not 0 <= q <= 1:
67+
165 2616483 2277023243.0 870.3 0.2 if not 0 <= q <= 1:
6868
166 raise ValueError("Quantile must be between 0 and 1")
69-
167 54600 30414699.0 557.0 0.1 if self.count == 0:
69+
167 2616483 1371491141.0 524.2 0.1 if self.count == 0:
7070
168 raise ValueError("Cannot compute quantile of empty sketch")
7171
169
72-
170 54600 29824194.0 546.2 0.1 rank = q * (self.count - 1)
72+
170 2616483 1518291210.0 580.3 0.1 rank = q * (self.count - 1)
7373
171
74-
172 54600 27603208.0 505.6 0.1 if self.cont_neg and self.negative_store is not None:
75-
173 54600 23921722.0 438.1 0.1 neg_count = self.negative_store.count
76-
174 54600 23138804.0 423.8 0.1 if rank < neg_count:
74+
172 2616483 1273997484.0 486.9 0.1 if self.cont_neg and self.negative_store is not None:
75+
173 2616483 1054785649.0 403.1 0.1 neg_count = self.negative_store.count
76+
174 2616483 1143741956.0 437.1 0.1 if rank < neg_count:
7777
175 # Handle negative values - use reversed rank
7878
176 reversed_rank = neg_count - rank - 1
7979
177 key = self.negative_store.key_at_rank(reversed_rank, lower=False)
8080
178 return -self.mapping.compute_value_from_index(key)
81-
179 54600 21073927.0 386.0 0.1 rank -= neg_count
81+
179 2616483 1138537472.0 435.1 0.1 rank -= neg_count
8282
180
83-
181 54600 22493715.0 412.0 0.1 if rank < self.zero_count:
83+
181 2616483 1081722072.0 413.4 0.1 if rank < self.zero_count:
8484
182 return 0.0
85-
183 54600 20079837.0 367.8 0.1 rank -= self.zero_count
85+
183 2616483 923188783.0 352.8 0.1 rank -= self.zero_count
8686
184
8787
185 # Use key_at_rank for consistency with storage implementation
88-
186 54600 2.47e+10 452297.2 98.3 key = self.positive_store.key_at_rank(rank)
89-
187 54600 192733597.0 3529.9 0.8 return self.mapping.compute_value_from_index(key)
88+
186 2616483 1.38e+12 528555.5 98.4 key = self.positive_store.key_at_rank(rank)
89+
187 2616483 1e+10 3836.4 0.7 return self.mapping.compute_value_from_index(key)
9090

91-
Total time: 0.0508712 s
91+
Total time: 2.48174 s
9292
File: /home/taira/Code/QuantileFlow/QuantileFlow/ddsketch/mapping/logarithmic.py
9393
Function: LogarithmicMapping.compute_bucket_index at line 29
9494

@@ -99,9 +99,9 @@ Line # Hits Time Per Hit % Time Line Contents
9999
31
100100
32 ceil(log_gamma(value)) = ceil(log(value) / log(gamma))
101101
33 """
102-
34 18047 50871154.0 2818.8 100.0 return math.ceil(math.log(value) * self.multiplier)
102+
34 867922 2481735173.0 2859.4 100.0 return math.ceil(math.log(value) * self.multiplier)
103103

104-
Total time: 0.0926335 s
104+
Total time: 4.76142 s
105105
File: /home/taira/Code/QuantileFlow/QuantileFlow/ddsketch/storage/contiguous.py
106106
Function: ContiguousStorage.add at line 110
107107

@@ -115,7 +115,7 @@ Line # Hits Time Per Hit % Time Line Contents
115115
115 key: The bucket index to add to.
116116
116 weight: The weight to add (default 1.0).
117117
117 """
118-
118 18047 63640127.0 3526.4 68.7 idx = self._get_index(key)
119-
119 18047 12528721.0 694.2 13.5 self.bins[idx] += weight
120-
120 18047 16464693.0 912.3 17.8 self.count += weight
118+
118 867922 3367877436.0 3880.4 70.7 idx = self._get_index(key)
119+
119 867922 659017479.0 759.3 13.8 self.bins[idx] += weight
120+
120 867922 734526582.0 846.3 15.4 self.count += weight
121121

0 commit comments

Comments
 (0)