Parse Go benchmark JSON output format.
(filepath)
| 144 | |
| 145 | |
| 146 | def 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 | |
| 184 | def parse_serialized_sizes(text): |