-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
113 additions
and
0 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,23 @@ | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
|
||
use serde_json; | ||
use std::fs; | ||
use std::path::Path; | ||
|
||
use moyo::base::{AngleTolerance, Cell}; | ||
use moyo::data::Setting; | ||
use moyo::MoyoDataset; | ||
|
||
pub fn benchmark(c: &mut Criterion) { | ||
let path = Path::new("tests/assets/mp-1201492.json"); | ||
let cell: Cell = serde_json::from_str(&fs::read_to_string(&path).unwrap()).unwrap(); | ||
let symprec = 1e-4; | ||
let angle_tolerance = AngleTolerance::Default; | ||
let setting = Setting::Standard; | ||
c.bench_function("dataset_clathrate_Si", |b| { | ||
b.iter(|| MoyoDataset::new(&cell, symprec, angle_tolerance, setting)) | ||
}); | ||
} | ||
|
||
criterion_group!(benches, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use criterion::{criterion_group, criterion_main, BenchmarkId, Criterion, Throughput}; | ||
|
||
use nalgebra::{matrix, vector}; | ||
|
||
use moyo::base::{Cell, Lattice, Position}; | ||
use moyo::search::{solve_correspondence, solve_correspondence_naive, PeriodicKdTree}; | ||
|
||
/// O(num_atoms^3) | ||
fn naive(reduced_cell: &Cell) { | ||
let num_atoms = reduced_cell.num_atoms(); | ||
let symprec = 1e-5; | ||
for j in 0..num_atoms { | ||
let translation = reduced_cell.positions[j] - reduced_cell.positions[0]; | ||
let new_positions: Vec<Position> = reduced_cell | ||
.positions | ||
.iter() | ||
.map(|pos| pos + translation) | ||
.collect(); | ||
|
||
solve_correspondence_naive(reduced_cell, &new_positions, symprec); | ||
} | ||
} | ||
|
||
/// O(num_atoms^2 * log(num_atoms)) | ||
fn kdtree(reduced_cell: &Cell) { | ||
let num_atoms = reduced_cell.num_atoms(); | ||
let symprec = 1e-5; | ||
let pkdtree = PeriodicKdTree::new(reduced_cell, symprec); | ||
for j in 0..num_atoms { | ||
let translation = reduced_cell.positions[j] - reduced_cell.positions[0]; | ||
let new_positions: Vec<Position> = reduced_cell | ||
.positions | ||
.iter() | ||
.map(|pos| pos + translation) | ||
.collect(); | ||
|
||
solve_correspondence(&pkdtree, reduced_cell, &new_positions); | ||
} | ||
} | ||
|
||
fn cell_for_benchmark(n: usize) -> Cell { | ||
let mut positions = vec![]; | ||
let mut numbers = vec![]; | ||
for i in 0..n { | ||
for j in 0..n { | ||
for k in 0..n { | ||
positions.push(vector![ | ||
i as f64 / n as f64, | ||
j as f64 / n as f64, | ||
k as f64 / n as f64 | ||
]); | ||
numbers.push(0); | ||
} | ||
} | ||
} | ||
|
||
Cell::new( | ||
Lattice::new(matrix![ | ||
n as f64, 0.0, 0.0; | ||
0.0, n as f64, 0.0; | ||
0.0, 0.0, n as f64; | ||
]), | ||
positions, | ||
numbers, | ||
) | ||
} | ||
|
||
pub fn benchmark(c: &mut Criterion) { | ||
let mut group = c.benchmark_group("translation search"); | ||
for n in 1..=8 { | ||
let cell = cell_for_benchmark(n); | ||
group.throughput(Throughput::Elements(cell.num_atoms() as u64)); | ||
group.bench_with_input(BenchmarkId::new("naive", n), &cell, |b, cell| { | ||
b.iter(|| naive(&cell)); | ||
}); | ||
group.bench_with_input(BenchmarkId::new("kdtree", n), &cell, |b, cell| { | ||
b.iter(|| kdtree(&cell)); | ||
}); | ||
} | ||
group.finish(); | ||
} | ||
|
||
criterion_group!(benches, benchmark); | ||
criterion_main!(benches); |