Skip to content

Commit

Permalink
added one last bench
Browse files Browse the repository at this point in the history
  • Loading branch information
Autoparallel committed Aug 23, 2023
1 parent f8be46d commit dd4111c
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,14 @@ The closest benchmark we have to Arbiter is running [Anvil](https://github.com/f

| Operation | Arbiter | Anvil | Relative Difference |
|-----------------|------------|--------------|---------------------|
| Deploy | 254.873µs | 8.525ms | ~33.44x |
| Stateless Call | 4.657507ms | 14.605913ms | ~3.14x |
| Stateful Call | 921.762µs | 160.975985ms | ~174.64x |
| Deploy | 241.819µs | 8.215446ms | ~33.97x |
| Lookup | 480.319µs | 13.052063ms | ~27.17x |
| Stateless Call | 4.03235ms | 10.238771ms | ~2.53x |
| Stateful Call | 843.296µs | 153.102478ms | ~181.55x |

The above can be described by:
- Deploy: Deploying a contract to the EVM. We deployed `ArbiterToken` and `ArbiterMath` in this call.
- Lookup: Looking up a the `balanceOf` for a client's address for `ArbiterToken`.
- Stateless Call: Calling a contract that does not mutate state. We called `ArbiterMath`'s `cdf` function 100 times in this call.
- Stateful Call: Calling a contract that mutates state. We called `ArbiterToken`'s `mint` function 100 times in this call.

Expand Down
26 changes: 26 additions & 0 deletions arbiter-core/benches/bench.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const NUM_LOOP_STEPS: usize = 100;
#[derive(Debug)]
struct BenchDurations {
deploy: Duration,
lookup: Duration,
stateless_call: Duration,
stateful_call: Duration,
}
Expand Down Expand Up @@ -72,18 +73,21 @@ async fn main() -> Result<()> {
let sum_durations = durations.iter().fold(
BenchDurations {
deploy: Duration::default(),
lookup: Duration::default(),
stateless_call: Duration::default(),
stateful_call: Duration::default(),
},
|acc, duration| BenchDurations {
deploy: acc.deploy + duration.deploy,
lookup: acc.lookup + duration.lookup,
stateless_call: acc.stateless_call + duration.stateless_call,
stateful_call: acc.stateful_call + duration.stateful_call,
},
);

let average_durations = BenchDurations {
deploy: sum_durations.deploy / NUM_BENCH_ITERATIONS as u32,
lookup: sum_durations.lookup / NUM_BENCH_ITERATIONS as u32,
stateless_call: sum_durations.stateless_call / NUM_BENCH_ITERATIONS as u32,
stateful_call: sum_durations.stateful_call / NUM_BENCH_ITERATIONS as u32,
};
Expand All @@ -97,6 +101,7 @@ async fn main() -> Result<()> {
async fn bencher<M: Middleware + 'static>(client: Arc<M>, label: &str) -> Result<BenchDurations> {
// Track the duration for each part of the benchmark.
let mut total_deploy_duration = 0;
let mut total_lookup_duration = 0;
let mut total_stateless_call_duration = 0;
let mut total_stateful_call_duration = 0;

Expand All @@ -105,6 +110,11 @@ async fn bencher<M: Middleware + 'static>(client: Arc<M>, label: &str) -> Result
let (arbiter_math, arbiter_token, deploy_duration) = deployments(client.clone(), label).await?;
total_deploy_duration += deploy_duration.as_micros();

// Call `balance_of` `NUM_LOOP_STEPS` times on `ArbiterToken` and tally up how
// long basic lookups take.
let lookup_duration = lookup(arbiter_token.clone(), label).await?;
total_lookup_duration += lookup_duration.as_micros();

// Call `cdf` `NUM_LOOP_STEPS` times on `ArbiterMath` and tally up how long this
// takes.
let stateless_call_duration = stateless_call_loop(arbiter_math, label).await?;
Expand All @@ -118,6 +128,7 @@ async fn bencher<M: Middleware + 'static>(client: Arc<M>, label: &str) -> Result

Ok(BenchDurations {
deploy: Duration::from_micros(total_deploy_duration as u64),
lookup: Duration::from_micros(total_lookup_duration as u64),
stateless_call: Duration::from_micros(total_stateless_call_duration as u64),
stateful_call: Duration::from_micros(total_stateful_call_duration as u64),
})
Expand Down Expand Up @@ -181,6 +192,21 @@ async fn deployments<M: Middleware + 'static>(
Ok((arbiter_math, arbiter_token, duration))
}

async fn lookup<M: Middleware + 'static>(
arbiter_token: ArbiterToken<M>,
label: &str,
) -> Result<Duration> {
let address = arbiter_token.client().default_sender().unwrap();
let start = Instant::now();
for _ in 0..NUM_LOOP_STEPS {
arbiter_token.balance_of(address).call().await?;
}
let duration = start.elapsed();
info!("Time elapsed in {} cdf loop is: {:?}", label, duration);

Ok(duration)
}

async fn stateless_call_loop<M: Middleware + 'static>(
arbiter_math: ArbiterMath<M>,
label: &str,
Expand Down

0 comments on commit dd4111c

Please # to comment.