Skip to content

Commit

Permalink
use if-else block instead of Return: +benches
Browse files Browse the repository at this point in the history
  • Loading branch information
agryaznov committed Nov 18, 2022
1 parent 810abd1 commit 6f43fbc
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
16 changes: 8 additions & 8 deletions BENCHMARKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,49 +42,49 @@

| | `with host_function::Injector` | `with mutable_global::Injector` |
|:-------|:----------------------------------------|:----------------------------------------- |
| | `17.89 s` (✅ **1.00x**) | `19.79 s` (✅ **1.11x slower**) |
| | `20.81 s` (✅ **1.00x**) | `20.20 s` (✅ **1.03x faster**) |

### recursive_ok, instrumented

| | `with host_function::Injector` | `with mutable_global::Injector` |
|:-------|:----------------------------------------|:----------------------------------------- |
| | `502.19 us` (✅ **1.00x**) | `555.46 us` (**1.11x slower**) |
| | `367.11 us` (✅ **1.00x**) | `585.39 us` (*1.59x slower*) |

### fibonacci_recursive, instrumented

| | `with host_function::Injector` | `with mutable_global::Injector` |
|:-------|:----------------------------------------|:----------------------------------------- |
| | `10.68 us` (✅ **1.00x**) | `14.35 us` (❌ *1.34x slower*) |
| | `9.15 us` (✅ **1.00x**) | `13.56 us` (❌ *1.48x slower*) |

### factorial_recursive, instrumented

| | `with host_function::Injector` | `with mutable_global::Injector` |
|:-------|:----------------------------------------|:----------------------------------------- |
| | `1.45 us` (✅ **1.00x**) | `1.86 us` (❌ *1.29x slower*) |
| | `1.50 us` (✅ **1.00x**) | `1.98 us` (❌ *1.32x slower*) |

### count_until, instrumented

| | `with host_function::Injector` | `with mutable_global::Injector` |
|:-------|:----------------------------------------|:----------------------------------------- |
| | `5.47 ms` (✅ **1.00x**) | `7.83 ms` (❌ *1.43x slower*) |
| | `5.03 ms` (✅ **1.00x**) | `8.13 ms` (❌ *1.62x slower*) |

### memory_vec_add, instrumented

| | `with host_function::Injector` | `with mutable_global::Injector` |
|:-------|:----------------------------------------|:----------------------------------------- |
| | `5.82 ms` (✅ **1.00x**) | `7.98 ms` (❌ *1.37x slower*) |
| | `6.21 ms` (✅ **1.00x**) | `8.45 ms` (❌ *1.36x slower*) |

### wasm_kernel::tiny_keccak, instrumented

| | `with host_function::Injector` | `with mutable_global::Injector` |
|:-------|:----------------------------------------|:----------------------------------------- |
| | `997.62 us` (✅ **1.00x**) | `1.14 ms` (❌ *1.14x slower*) |
| | `925.22 us` (✅ **1.00x**) | `1.08 ms` (❌ *1.17x slower*) |

### global_bump, instrumented

| | `with host_function::Injector` | `with mutable_global::Injector` |
|:-------|:----------------------------------------|:----------------------------------------- |
| | `3.61 ms` (✅ **1.00x**) | `6.22 ms` (❌ *1.72x slower*) |
| | `3.79 ms` (✅ **1.00x**) | `7.03 ms` (❌ *1.86x slower*) |

---
Made with [criterion-table](https://github.com/nu11ptr/criterion-table)
Expand Down
2 changes: 1 addition & 1 deletion benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ criterion_group!(
name = coremark;
config = Criterion::default()
.sample_size(10)
.measurement_time(Duration::from_millis(250000))
.measurement_time(Duration::from_millis(275000))
.warm_up_time(Duration::from_millis(1000));
targets =
gas_metered_coremark,
Expand Down
9 changes: 4 additions & 5 deletions src/gas_metering/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ pub mod host_function {
/// # Note
///
/// Not for all execution engines this method gives performance wins compared to using an [external
/// host function](host_function). Still in any case a Wasm module instrumented with this method
/// will likely have a larger size. See benchmarks and size overhead tests for examples of how to
/// make measurements needed to decide which gas metering method is better in your particular case.
/// host function](host_function). See benchmarks and size overhead tests for examples of how to
/// make measurements needed to decide which gas metering method is better for your particular case.
///
/// # Warning
///
Expand Down Expand Up @@ -109,13 +108,13 @@ pub mod mutable_global {
Instruction::GetLocal(0),
Instruction::I64Sub,
Instruction::SetGlobal(gas_global_idx),
Instruction::Return,
Instruction::End,
Instruction::Else,
// sentinel val u64::MAX
Instruction::I64Const(-1i64), // non-charged instruction
Instruction::SetGlobal(gas_global_idx), // non-charged instruction
Instruction::Unreachable, // non-charged instruction
Instruction::End,
Instruction::End,
];

// calculate gas used for the gas charging func execution itself
Expand Down

0 comments on commit 6f43fbc

Please sign in to comment.