-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add neighbors_cpp_vs_neighbors_z_rust_benchmark.rs
& minor refactoring
- Loading branch information
1 parent
44635f6
commit d5833d5
Showing
6 changed files
with
99 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion}; | ||
use std::process::Command; | ||
use std::time::Duration; | ||
|
||
use mimalloc::MiMalloc; | ||
#[global_allocator] | ||
//static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; | ||
static GLOBAL: MiMalloc = MiMalloc; | ||
|
||
fn benchmark_binary(binary_path: &str) -> Duration { | ||
// Run the binary and time its execution | ||
let start = std::time::Instant::now(); | ||
let status = Command::new(binary_path) | ||
.status() | ||
.expect("Failed to execute binary"); | ||
|
||
if !status.success() { | ||
panic!("Binary did not run successfully"); | ||
} | ||
|
||
start.elapsed() | ||
} | ||
|
||
//Benchmark using the executable "neighbors_z_rust_executable__..." and "neighbors_cpp_executable__..." | ||
fn neighbors_cpp_vs_neighbors_z_rust_benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("neighbors_cpp_vs_neighbors_z_rust_benchmark"); | ||
|
||
let binary_folder = "target/release/"; | ||
|
||
let executables = ["neighbors_cpp_executable__inputfile_lj_cube_1000_timestep_0_0001_nbiterations_50k_cutoff_1_5", "neighbors_z_rust_executable__inputfile_lj_cube_1000_timestep_0_0001_nbiterations_50k_cutoff_1_5"]; | ||
|
||
group.sample_size(20); | ||
|
||
for executable in executables { | ||
let executable_path = binary_folder.to_owned() + executable; | ||
|
||
println!("Benchmark executable: {}", executable_path); | ||
|
||
group.bench_function(BenchmarkId::new(&executable_path, "__Benchmark"), |b| { | ||
b.iter(|| { | ||
benchmark_binary(&executable_path); | ||
}); | ||
}); | ||
} | ||
|
||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, neighbors_cpp_vs_neighbors_z_rust_benchmark); | ||
criterion_main!(benches); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use rsmd::md_implementation::{neighbors_z::NeighborListZ, xyz::read_xyz}; | ||
|
||
use mimalloc::MiMalloc; | ||
#[global_allocator] | ||
//static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc; | ||
static GLOBAL: MiMalloc = MiMalloc; | ||
|
||
const TIMESTEP: f64 = 0.0001; | ||
const NB_ITERATIONS: u32 = 50_000; | ||
const CUTOFF_RADIUS: f64 = 1.5; | ||
const INPUT_PATH: &str = "input_files/lj_cube_1000.xyz"; | ||
|
||
//Executable for benchmark "neighbors_cpp_vs_neighbors_z_rust_benchmark.rs" | ||
fn main() { | ||
let mut atoms = read_xyz(INPUT_PATH.to_string()).expect("Failed to load atoms configuration."); | ||
|
||
let mut neighbor_list: NeighborListZ = NeighborListZ::new(); | ||
|
||
for i in 0..NB_ITERATIONS { | ||
atoms.verlet_step1(TIMESTEP.into()); | ||
if i % 100 != 0 { | ||
neighbor_list.update(&mut atoms, CUTOFF_RADIUS, false); | ||
} else { | ||
neighbor_list.update(&mut atoms, CUTOFF_RADIUS, true); | ||
} | ||
atoms.verlet_step2(TIMESTEP.into()); | ||
} | ||
} |