MCPcopy Create free account
hub / github.com/apache/fory / parse_benchmark_json

Function parse_benchmark_json

benchmarks/go/benchmark_report.py:146–181  ·  view source on GitHub ↗

Parse Go benchmark JSON output format.

(filepath)

Source from the content-addressed store, hash-verified

144
145
146def parse_benchmark_json(filepath):
147 """Parse Go benchmark JSON output format."""
148 results = defaultdict(lambda: defaultdict(lambda: defaultdict(list)))
149
150 with open(filepath, "r") as f:
151 for line in f:
152 try:
153 data = json.loads(line)
154 if data.get("Action") == "output" and "Benchmark" in data.get(
155 "Output", ""
156 ):
157 output = data["Output"]
158 # Match benchmark result lines
159 match = re.match(
160 r"Benchmark(\w+)_(\w+)_(Serialize|Deserialize)-\d+\s+\d+\s+([\d.]+)\s+ns/op",
161 output,
162 )
163 if match:
164 serializer = match.group(1).lower()
165 datatype = normalize_datatype(match.group(2).lower())
166 operation = match.group(3).lower()
167 ns_per_op = float(match.group(4))
168
169 results[datatype][operation][serializer].append(ns_per_op)
170 except json.JSONDecodeError:
171 continue
172
173 # Average multiple runs
174 final_results = defaultdict(lambda: defaultdict(dict))
175 for datatype, ops in results.items():
176 for op, serializers in ops.items():
177 for serializer, times in serializers.items():
178 if times:
179 final_results[datatype][op][serializer] = sum(times) / len(times)
180
181 return final_results
182
183
184def parse_serialized_sizes(text):

Callers 1

mainFunction · 0.85

Calls 6

itemsMethod · 0.80
normalize_datatypeFunction · 0.70
getMethod · 0.65
loadsMethod · 0.45
matchMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected