Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
Add benchmark for plotting (paritytech#292)
Browse files Browse the repository at this point in the history
* Add benchmark for plotting as an example

* Change arguments from megabytes to pieces

* Make benchmark a cargo benchmark without harness

Co-authored-by: Nazar Mokrynskyi <nazar@mokrynskyi.com>
  • Loading branch information
i1i1 and nazar-pc authored Mar 24, 2022
1 parent 64b1658 commit 76d20af
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
4 changes: 4 additions & 0 deletions crates/subspace-farmer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ default = []
cuda = [
"subspace-solving/cuda",
]

[[bench]]
name = "plot-write"
harness = false
34 changes: 34 additions & 0 deletions crates/subspace-farmer/benches/plot-write.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::sync::Arc;

use rand::prelude::*;
use subspace_core_primitives::PIECE_SIZE;
use subspace_farmer::Plot;
use tempfile::TempDir;

#[tokio::main]
async fn main() {
let batch_size = 4096; // 16M
let piece_count = 2u64.pow(30); // 1G
let base_directory = TempDir::new_in(std::env::current_dir().unwrap()).unwrap();

let mut pieces = Vec::with_capacity(batch_size as usize * PIECE_SIZE);
pieces.resize(batch_size as usize * PIECE_SIZE, 0u8);
rand::thread_rng().fill(&mut pieces[..]);
let pieces = Arc::new(pieces.try_into().unwrap());

let plot = Plot::open_or_create(&base_directory).unwrap();

let start = std::time::Instant::now();

for index in (0..piece_count / batch_size).map(|i| i * batch_size) {
plot.write_many(Arc::clone(&pieces), index as u64).unwrap();
}
drop(plot);

let took = start.elapsed();
let write_size = piece_count * PIECE_SIZE as u64 / 1024 / 1024;
eprintln!(
"Writing {write_size}M to disk took {took:?}. Speed is around {:.2} M/s",
write_size as f64 / took.as_secs_f64()
);
}
2 changes: 1 addition & 1 deletion crates/subspace-farmer/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl Plot {
}

/// Writes a piece/s to the plot by index, will overwrite if piece exists (updates)
pub(crate) fn write_many(
pub fn write_many(
&self,
encodings: Arc<FlatPieces>,
first_index: PieceIndex,
Expand Down

0 comments on commit 76d20af

Please sign in to comment.