diff options
author | Lars Wirzenius <liw@liw.fi> | 2020-11-25 08:11:57 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2020-11-25 10:37:38 +0200 |
commit | af2c79d1963c49402d5b47e916ffb6b0210c79d1 (patch) | |
tree | eea17935c844844a6a4ca5620ee5dae4ede6ce14 /src/benchmark.rs | |
parent | 02684a9c68ffc87d20ba89852fbcba43ed521039 (diff) | |
download | obnam2-af2c79d1963c49402d5b47e916ffb6b0210c79d1.tar.gz |
feat: add programs to benchmark server chunk storage
Diffstat (limited to 'src/benchmark.rs')
-rw-r--r-- | src/benchmark.rs | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/benchmark.rs b/src/benchmark.rs new file mode 100644 index 0000000..b313868 --- /dev/null +++ b/src/benchmark.rs @@ -0,0 +1,32 @@ +use crate::chunk::DataChunk; +use crate::chunkid::ChunkId; +use crate::chunkmeta::ChunkMeta; + +// Generate a desired number of empty data chunks with id and metadata. +pub struct ChunkGenerator { + goal: u32, + next: u32, +} + +impl ChunkGenerator { + pub fn new(goal: u32) -> Self { + Self { goal, next: 0 } + } +} + +impl Iterator for ChunkGenerator { + type Item = (ChunkId, String, ChunkMeta, DataChunk); + + fn next(&mut self) -> Option<Self::Item> { + if self.next >= self.goal { + None + } else { + let id = ChunkId::new(); + let checksum = id.sha256(); + let meta = ChunkMeta::new(&checksum); + let chunk = DataChunk::new(vec![]); + self.next += 1; + Some((id, checksum, meta, chunk)) + } + } +} |