This repository has been archived by the owner on Feb 21, 2024. It is now read-only.
forked from paritytech/substrate
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add benchmark for plotting (paritytech#292)
* 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
Showing
3 changed files
with
39 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,3 +62,7 @@ default = [] | |
cuda = [ | ||
"subspace-solving/cuda", | ||
] | ||
|
||
[[bench]] | ||
name = "plot-write" | ||
harness = false |
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,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() | ||
); | ||
} |
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