Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add benchmark script #488

Merged
merged 6 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/.idea/
/.vagrant
/flamegraph.svg
/benchmark
/index.lmdb
/index.redb
/ord.log
Expand Down
21 changes: 21 additions & 0 deletions bin/benchmark
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -euxo pipefail

rm -rf benchmark
mkdir benchmark

for HEIGHT_LIMIT in 100 250 500 1000 2000; do
sudo \
CARGO_PROFILE_RELEASE_DEBUG=true \
RUST_LOG=info \
cargo flamegraph \
--deterministic \
--bin ord \
--output benchmark/$HEIGHT_LIMIT.svg \
-- \
--chain signet \
--data-dir benchmark \
--height-limit $HEIGHT_LIMIT \
index
done
3 changes: 3 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,6 @@ graph:

flamegraph:
CARGO_PROFILE_RELEASE_DEBUG=true sudo cargo flamegraph -- index

benchmark:
./bin/benchmark
8 changes: 8 additions & 0 deletions src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pub(crate) struct Index {
client: Client,
database: Database,
database_path: PathBuf,
height_limit: Option<Height>,
}

pub(crate) enum List {
Expand Down Expand Up @@ -61,6 +62,7 @@ impl Index {
client,
database,
database_path,
height_limit: options.height_limit,
})
}

Expand Down Expand Up @@ -121,6 +123,12 @@ impl Index {

pub(crate) fn index_ranges(&self) -> Result {
loop {
if let Some(height_limit) = self.height_limit {
if self.height()? >= height_limit {
break;
}
}

let mut wtx = self.database.begin_write()?;

let done = self.index_block(&mut wtx)?;
Expand Down
2 changes: 2 additions & 0 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ pub(crate) struct Options {
data_dir: Option<PathBuf>,
#[clap(long)]
bitcoin_data_dir: Option<PathBuf>,
#[clap(long)]
pub(crate) height_limit: Option<Height>,
}

#[derive(ValueEnum, Copy, Clone, Debug)]
Expand Down
16 changes: 16 additions & 0 deletions tests/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,19 @@ fn custom_index_size() {
1 << 20
);
}

#[test]
fn height_limit() {
Test::new()
.command("find 5000000000")
.expected_stdout("150ba822b458a19615e70a604d8dd9d3482fc165fa4e9cc150d74e11916ce8ae:0:0\n")
.blocks(1)
.run();

Test::new()
.command("--height-limit 0 find 5000000000")
.expected_stderr("error: Ordinal has not been mined as of index height\n")
.expected_status(1)
.blocks(1)
.run();
}