| 540 | } |
| 541 | |
| 542 | fn run(config: Config) -> Result<()> { |
| 543 | config.validate()?; |
| 544 | let parent = config |
| 545 | .output |
| 546 | .parent() |
| 547 | .filter(|p| !p.as_os_str().is_empty()) |
| 548 | .unwrap_or(Path::new(".")); |
| 549 | fs::create_dir_all(parent)?; |
| 550 | let binary = std::env::current_exe()?; |
| 551 | let binary_hash = blake3::hash(&fs::read(&binary)?).to_hex().to_string(); |
| 552 | let mut fixtures = [ |
| 553 | Fixture::new(parent, &config, false)?, |
| 554 | Fixture::new(parent, &config, true)?, |
| 555 | ]; |
| 556 | for view in ["dev", "bench-near", "bench-far"] { |
| 557 | let left = &fixtures[0].golden[view]; |
| 558 | let right = &fixtures[1].golden[view]; |
| 559 | ensure!( |
| 560 | left.iter() |
| 561 | .zip(right) |
| 562 | .all(|(a, b)| a.path == b.path && a.content == b.content && a.mode == b.mode), |
| 563 | "graph/span fixture mismatch for {view}" |
| 564 | ); |
| 565 | } |
| 566 | let mut samples = Vec::new(); |
| 567 | for iteration in 0..config.warmups + config.iterations { |
| 568 | for case in CASES { |
| 569 | for offset in 0..2 { |
| 570 | let index = (iteration + offset) % 2; |
| 571 | let measured = sample( |
| 572 | &mut fixtures[index], |
| 573 | case, |
| 574 | iteration.saturating_sub(config.warmups), |
| 575 | ) |
| 576 | .with_context(|| { |
| 577 | format!("{} {case}, iteration {iteration}", fixtures[index].backend) |
| 578 | })?; |
| 579 | if iteration >= config.warmups { |
| 580 | samples.push(measured); |
| 581 | } |
| 582 | } |
| 583 | } |
| 584 | } |
| 585 | ensure!( |
| 586 | blake3::hash(&fs::read(&binary)?).to_hex().as_str() == binary_hash, |
| 587 | "benchmark binary changed during run" |
| 588 | ); |
| 589 | let setup: Vec<_> = fixtures.iter().map(|f| serde_json::json!({"backend":f.backend,"setup_ns":f.setup_ns, |
| 590 | "database_bytes_after_samples":fs::metadata(f.directory.path().join(".atomic/atomic.redb")).map(|m|m.len()).ok()})).collect(); |
| 591 | let mut retained = Vec::new(); |
| 592 | for fixture in fixtures { |
| 593 | drop(fixture.repo); |
| 594 | if config.keep_fixtures { |
| 595 | retained.push(fixture.directory.keep()); |
| 596 | } |
| 597 | } |
| 598 | let report = serde_json::json!({"schema":1,"config":config,"binary_blake3":binary_hash, |
| 599 | "debug_build":cfg!(debug_assertions),"platform":{"os":std::env::consts::OS,"arch":std::env::consts::ARCH}, |