将benchmark结果保存到CSV文件
(self)
| 327 | self.print_summary(total_duration) |
| 328 | |
| 329 | def save_results_to_csv(self): |
| 330 | """将benchmark结果保存到CSV文件""" |
| 331 | if not self.results: |
| 332 | print("⚠️ No results to save") |
| 333 | return |
| 334 | |
| 335 | # Use user-specified CSV path, otherwise use default path |
| 336 | if self.csv_output: |
| 337 | csv_file = self.csv_output |
| 338 | # Ensure parent directory exists |
| 339 | csv_file.parent.mkdir(parents=True, exist_ok=True) |
| 340 | else: |
| 341 | csv_file = self.stats_dir / f"embedding_benchmark.csv" |
| 342 | |
| 343 | print(f"\n💾 Saving results to: {csv_file}") |
| 344 | |
| 345 | try: |
| 346 | with open(csv_file, 'w', newline='') as f: |
| 347 | fieldnames = ['embedding_type', 'threads_1', 'threads_2', 'threads_4', 'threads_8'] |
| 348 | writer = csv.DictWriter(f, fieldnames=fieldnames) |
| 349 | |
| 350 | writer.writeheader() |
| 351 | for result in self.results: |
| 352 | writer.writerow(result) |
| 353 | |
| 354 | print(f"✅ Results saved successfully") |
| 355 | |
| 356 | # Also print table |
| 357 | print(f"\n📊 Benchmark Results:") |
| 358 | print(f"{'Type':<15} {'1 thread':<18} {'2 threads':<18} {'4 threads':<18} {'8 threads':<18}") |
| 359 | print("-" * 87) |
| 360 | for result in self.results: |
| 361 | t1 = result['threads_1'] if result['threads_1'] else "N/A" |
| 362 | t2 = result['threads_2'] if result['threads_2'] else "N/A" |
| 363 | t4 = result['threads_4'] if result['threads_4'] else "N/A" |
| 364 | t8 = result['threads_8'] if result['threads_8'] else "N/A" |
| 365 | print(f"{result['embedding_type']:<15} {t1:<18} {t2:<18} {t4:<18} {t8:<18}") |
| 366 | |
| 367 | except Exception as e: |
| 368 | print(f"❌ Failed to save results: {e}") |
| 369 | |
| 370 | def print_summary(self, total_duration): |
| 371 | """Print quantization summary""" |
no outgoing calls
no test coverage detected