Skip to content

Commit 02dba91

Browse files
committed
criterion/monero-serai/
1 parent 1c768a6 commit 02dba91

File tree

10 files changed

+368
-5
lines changed

10 files changed

+368
-5
lines changed

Diff for: Cargo.lock

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: Cargo.toml

+6-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ members = [
1111
"criterion/cuprate-cryptonight",
1212
"criterion/cuprate-rpc-types",
1313
"criterion/cuprate-blockchain",
14+
"criterion/monero-serai",
1415
]
1516

1617
[profile.release]
@@ -86,10 +87,10 @@ futures = { version = "0.3", default-features = false }
8687
hex = { version = "0.4", default-features = false }
8788
hex-literal = { version = "0.4", default-features = false }
8889
indexmap = { version = "2", default-features = false }
89-
monero-serai = { git = "https://github.com/Cuprate/serai.git", rev = "d5205ce", default-features = false }
90+
monero-serai = { git = "https://github.com/Cuprate/cuprate", rev = "7b8756f", default-features = false }
9091
paste = { version = "1", default-features = false }
9192
pin-project = { version = "1", default-features = false }
92-
randomx-rs = { git = "https://github.com/Cuprate/randomx-rs.git", rev = "0028464", default-features = false }
93+
randomx-rs = { git = "https://github.com/Cuprate/cuprate", rev = "7b8756f", default-features = false }
9394
rand = { version = "0.8", default-features = false }
9495
rand_distr = { version = "0.4", default-features = false }
9596
rayon = { version = "1", default-features = false }
@@ -102,14 +103,14 @@ thread_local = { version = "1", default-features = false }
102103
tokio-util = { version = "0.7", default-features = false }
103104
tokio-stream = { version = "0.1", default-features = false }
104105
tokio = { version = "1", default-features = false }
105-
tower = { git = "https://github.com/Cuprate/tower.git", rev = "6c7faf0", default-features = false } # <https://github.com/tower-rs/tower/pull/796>
106+
tower = { git = "https://github.com/Cuprate/cuprate", rev = "7b8756f", default-features = false } # <https://github.com/tower-rs/tower/pull/796>
106107
tracing-subscriber = { version = "0.3", default-features = false }
107108
tracing = { version = "0.1", default-features = false }
108109

109110
criterion = { version = "0.5" }
110111
function_name = { version = "0.3" }
111-
monero-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "d5205ce" }
112-
monero-simple-request-rpc = { git = "https://github.com/Cuprate/serai.git", rev = "d5205ce" }
112+
monero-rpc = { git = "https://github.com/Cuprate/cuprate", rev = "7b8756f" }
113+
monero-simple-request-rpc = { git = "https://github.com/Cuprate/cuprate", rev = "7b8756f" }
113114
tempfile = { version = "3" }
114115
pretty_assertions = { version = "1" }
115116
proptest = { version = "1" }

Diff for: criterion/monero-serai/Cargo.toml

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[package]
2+
name = "monero-serai-criterion"
3+
version = "0.0.0"
4+
edition = "2021"
5+
description = "Criterion benchmarks for monero-serai"
6+
license = "MIT"
7+
authors = ["hinto-janai"]
8+
repository = "https://github.com/Cuprate/benches/tree/main/criterion/monero-serai"
9+
keywords = ["monero-serai", "criterion", "benchmark"]
10+
11+
[dependencies]
12+
cuprate-constants = { workspace = true, features = ["block"] }
13+
cuprate-helper = { workspace = true, features = ["cast", "map", "num", "tx"] }
14+
cuprate-test-utils = { workspace = true }
15+
16+
criterion = { workspace = true }
17+
function_name = { workspace = true }
18+
monero-serai = { workspace = true }
19+
serde_json = { workspace = true, features = ["default"] }
20+
21+
[[bench]]
22+
name = "main"
23+
harness = false
24+
25+
[lints]
26+
workspace = true

Diff for: criterion/monero-serai/benches/block.rs

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//! Benchmarks for [`block`] and [`alt_block`] functions.
2+
3+
#![allow(unused_attributes, unused_crate_dependencies)]
4+
5+
use criterion::{black_box as b, criterion_group, criterion_main, BatchSize, Criterion};
6+
use monero_serai::block::Block;
7+
8+
criterion_group! {
9+
name = benches;
10+
config = Criterion::default();
11+
targets = block_benches,
12+
}
13+
criterion_main!(benches);
14+
15+
fn block_benches(c: &mut Criterion) {
16+
let mut g = c.benchmark_group(format!("{} (block)", monero_serai_criterion::GROUP));
17+
18+
let blocks = monero_serai_criterion::blocks();
19+
20+
for (name, block) in &blocks {
21+
let vec = {
22+
let mut vec = vec![];
23+
block.write(&mut vec).unwrap();
24+
Vec::with_capacity(vec.capacity())
25+
};
26+
27+
g.bench_function(format!("write_{name}"), |c| {
28+
c.iter_batched(
29+
|| vec.clone(),
30+
|mut v| b(block.write(&mut v)),
31+
BatchSize::SmallInput,
32+
);
33+
});
34+
}
35+
36+
for (name, block) in &blocks {
37+
let bytes = block.serialize();
38+
g.bench_function(format!("read_{name}"), |c| {
39+
c.iter_with_large_drop(|| b(Block::read(&mut bytes.as_slice())));
40+
});
41+
}
42+
43+
for (name, block) in &blocks {
44+
g.bench_function(format!("serialize_{name}"), |c| {
45+
c.iter_with_large_drop(|| b(block.serialize()));
46+
});
47+
}
48+
49+
for (name, block) in &blocks {
50+
g.bench_function(format!("serialize_pow_hash_{name}"), |c| {
51+
c.iter_with_large_drop(|| b(block.serialize_pow_hash()));
52+
});
53+
}
54+
55+
for (name, block) in &blocks {
56+
g.bench_function(format!("hash_{name}"), |c| {
57+
c.iter(|| b(block.hash()));
58+
});
59+
}
60+
}

Diff for: criterion/monero-serai/benches/block_header.rs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//! Benchmarks for [`block`] and [`alt_block`] functions.
2+
3+
#![allow(unused_attributes, unused_crate_dependencies)]
4+
5+
use criterion::{black_box as b, criterion_group, criterion_main, BatchSize, Criterion};
6+
use monero_serai::block::BlockHeader;
7+
8+
criterion_group! {
9+
name = benches;
10+
config = Criterion::default();
11+
targets = block_header_benches,
12+
}
13+
criterion_main!(benches);
14+
15+
fn block_header_benches(c: &mut Criterion) {
16+
let mut g = c.benchmark_group(format!("{} (block_header)", monero_serai_criterion::GROUP));
17+
18+
let blocks = monero_serai_criterion::blocks();
19+
20+
for (name, block) in &blocks {
21+
let vec = {
22+
let mut vec = vec![];
23+
block.write(&mut vec).unwrap();
24+
Vec::with_capacity(vec.capacity())
25+
};
26+
27+
g.bench_function(format!("write_{name}"), |c| {
28+
c.iter_batched(
29+
|| vec.clone(),
30+
|mut v| b(block.write(&mut v)),
31+
BatchSize::SmallInput,
32+
);
33+
});
34+
}
35+
36+
for (name, block) in &blocks {
37+
let bytes = block.serialize();
38+
39+
g.bench_function(format!("read_{name}"), |c| {
40+
c.iter_with_large_drop(|| b(BlockHeader::read(&mut bytes.as_slice())));
41+
});
42+
}
43+
44+
for (name, block) in &blocks {
45+
g.bench_function(format!("serialize_{name}"), |c| {
46+
c.iter_with_large_drop(|| b(block.serialize()));
47+
});
48+
}
49+
}

Diff for: criterion/monero-serai/benches/input.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! Benchmarks for [`block`] and [`alt_block`] functions.
2+
3+
#![allow(unused_attributes, unused_crate_dependencies)]
4+
5+
use criterion::{black_box as b, criterion_group, criterion_main, BatchSize, Criterion};
6+
use monero_serai::transaction::Input;
7+
8+
criterion_group! {
9+
name = benches;
10+
config = Criterion::default();
11+
targets = input_benches,
12+
}
13+
criterion_main!(benches);
14+
15+
fn input_benches(c: &mut Criterion) {
16+
let mut g = c.benchmark_group(format!("{} (input)", monero_serai_criterion::GROUP));
17+
18+
let txs = b(monero_serai_criterion::txs());
19+
20+
for (name, tx) in &txs {
21+
for (i, input) in tx.prefix().inputs.iter().enumerate() {
22+
let vec = {
23+
let mut vec = vec![];
24+
input.write(&mut vec).unwrap();
25+
Vec::with_capacity(vec.capacity())
26+
};
27+
28+
g.bench_function(format!("write_{name}_{i}"), |c| {
29+
c.iter_batched(
30+
|| vec.clone(),
31+
|mut v| input.write(&mut v),
32+
BatchSize::SmallInput,
33+
);
34+
});
35+
}
36+
}
37+
38+
for (name, tx) in &txs {
39+
for (i, input) in tx.prefix().inputs.iter().enumerate() {
40+
let bytes = input.serialize();
41+
g.bench_function(format!("read_{name}_{i}"), |c| {
42+
c.iter(|| Input::read(&mut bytes.as_slice()));
43+
});
44+
}
45+
}
46+
47+
for (name, tx) in &txs {
48+
for (i, input) in tx.prefix().inputs.iter().enumerate() {
49+
g.bench_function(format!("serialize_{name}_{i}"), |c| {
50+
c.iter_with_large_drop(|| b(input.serialize()));
51+
});
52+
}
53+
}
54+
}

Diff for: criterion/monero-serai/benches/main.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! `cuprate_helper` benchmarks.
2+
#![allow(unused_crate_dependencies)]
3+
4+
mod block;
5+
mod block_header;
6+
mod input;
7+
mod output;
8+
mod tx;
9+
10+
criterion::criterion_main! {
11+
block::benches,
12+
block_header::benches,
13+
tx::benches,
14+
output::benches,
15+
input::benches,
16+
}

Diff for: criterion/monero-serai/benches/output.rs

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
//! Benchmarks for [`block`] and [`alt_block`] functions.
2+
3+
#![allow(unused_attributes, unused_crate_dependencies)]
4+
5+
use criterion::{black_box as b, criterion_group, criterion_main, BatchSize, Criterion};
6+
use monero_serai::transaction::Output;
7+
8+
criterion_group! {
9+
name = benches;
10+
config = Criterion::default();
11+
targets = output_benches,
12+
}
13+
criterion_main!(benches);
14+
15+
fn output_benches(c: &mut Criterion) {
16+
let mut g = c.benchmark_group(format!("{} (output)", monero_serai_criterion::GROUP));
17+
18+
let txs = b(monero_serai_criterion::txs());
19+
20+
for (name, tx) in &txs {
21+
for (i, output) in tx.prefix().outputs.iter().enumerate() {
22+
let vec = {
23+
let mut vec = vec![];
24+
output.write(&mut vec).unwrap();
25+
Vec::with_capacity(vec.capacity())
26+
};
27+
28+
g.bench_function(format!("write_{name}_{i}"), |c| {
29+
c.iter_batched(
30+
|| vec.clone(),
31+
|mut v| output.write(&mut v),
32+
BatchSize::SmallInput,
33+
);
34+
});
35+
}
36+
}
37+
38+
for (name, tx) in &txs {
39+
let rct = tx.version() == 2;
40+
for (i, output) in tx.prefix().outputs.iter().enumerate() {
41+
let bytes = output.serialize();
42+
g.bench_function(format!("read_{name}_{i}"), |c| {
43+
c.iter(|| Output::read(rct, &mut bytes.as_slice()));
44+
});
45+
}
46+
}
47+
48+
for (name, tx) in &txs {
49+
for (i, output) in tx.prefix().outputs.iter().enumerate() {
50+
g.bench_function(format!("serialize_{name}_{i}"), |c| {
51+
c.iter_with_large_drop(|| b(output.serialize()));
52+
});
53+
}
54+
}
55+
}

Diff for: criterion/monero-serai/benches/tx.rs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//! Benchmarks for [`block`] and [`alt_block`] functions.
2+
3+
#![allow(unused_attributes, unused_crate_dependencies)]
4+
5+
use criterion::{black_box as b, criterion_group, criterion_main, BatchSize, Criterion};
6+
use monero_serai::transaction::{NotPruned, Transaction};
7+
8+
criterion_group! {
9+
name = benches;
10+
config = Criterion::default();
11+
targets = tx_benches,
12+
}
13+
criterion_main!(benches);
14+
15+
fn tx_benches(c: &mut Criterion) {
16+
let mut g = c.benchmark_group(format!("{} (tx)", monero_serai_criterion::GROUP));
17+
18+
let txs = monero_serai_criterion::txs();
19+
20+
for (name, tx) in &txs {
21+
let vec = {
22+
let mut vec = vec![];
23+
tx.write(&mut vec).unwrap();
24+
Vec::with_capacity(vec.capacity())
25+
};
26+
27+
g.bench_function(format!("write_{name}"), |c| {
28+
c.iter_batched(
29+
|| vec.clone(),
30+
|mut v| b(tx.write(&mut v)),
31+
BatchSize::SmallInput,
32+
);
33+
});
34+
}
35+
36+
for (name, tx) in &txs {
37+
let bytes = tx.serialize();
38+
g.bench_function(format!("read_{name}"), |c| {
39+
c.iter_with_large_drop(|| b(Transaction::<NotPruned>::read(&mut bytes.as_slice())));
40+
});
41+
}
42+
43+
for (name, tx) in &txs {
44+
g.bench_function(format!("serialize_{name}"), |c| {
45+
c.iter_with_large_drop(|| b(tx.serialize()));
46+
});
47+
}
48+
49+
for (name, tx) in &txs {
50+
g.bench_function(format!("hash_{name}"), |c| {
51+
c.iter(|| b(tx.hash()));
52+
});
53+
}
54+
55+
for (name, tx) in &txs {
56+
g.bench_function(format!("signature_hash_{name}"), |c| {
57+
c.iter(|| b(tx.signature_hash()));
58+
});
59+
}
60+
61+
for (name, tx) in &txs {
62+
g.bench_function(format!("weight_{name}"), |c| {
63+
c.iter(|| b(tx.weight()));
64+
});
65+
}
66+
}

0 commit comments

Comments
 (0)