Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit 14f9563

Browse files
authored
Merge pull request #152 from confio/mixer-mixing-fn-benches
Mixer mixing fn benches
2 parents 77fe014 + 962a911 commit 14f9563

File tree

2 files changed

+23
-12
lines changed

2 files changed

+23
-12
lines changed

contracts/tg4-mixer/Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ bench = false
2020
backtraces = ["cosmwasm-std/backtraces"]
2121
# use library feature to disable all instantiate/execute/query exports
2222
library = []
23-
benches = [ "cosmwasm-vm" ]
2423

2524
[dependencies]
2625
cosmwasm-std = "1.0.0"
@@ -38,16 +37,14 @@ tg4 = { path = "../../packages/tg4", version = "0.10.0" }
3837
tg-utils = { path = "../../packages/utils", version = "0.10.0" }
3938
tg-bindings = { path = "../../packages/bindings", version = "0.10.0" }
4039

41-
# bench dependencies
42-
cosmwasm-vm = { version = "1.0.0", optional = true }
43-
4440
[dev-dependencies]
4541
cosmwasm-schema = "1.0.0"
42+
# bench dependencies
43+
cosmwasm-vm = { version = "1.0.0" }
4644
cw-multi-test = "0.13.4"
4745
tg4-engagement = { path = "../tg4-engagement", version = "0.10.0", features = ["library"] }
4846
tg4-stake = { path = "../tg4-stake", version = "0.10.0", features = ["library"] }
4947

5048
[[bench]]
5149
name = "main"
5250
harness = false
53-
required-features = [ "benches" ]

contracts/tg4-mixer/benches/main.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@
33
//! Then running `cargo bench` will validate we can properly call into that generated Wasm.
44
//!
55
use cosmwasm_std::{Decimal, Uint64};
6-
use cosmwasm_vm::from_slice;
7-
use cosmwasm_vm::testing::{mock_env, mock_instance, query};
6+
use cosmwasm_vm::testing::{
7+
mock_env, mock_instance_with_options, query, MockApi, MockInstanceOptions, MockQuerier,
8+
MockStorage,
9+
};
10+
use cosmwasm_vm::{features_from_csv, from_slice, Instance};
811

912
use tg4_mixer::msg::PoEFunctionType::{AlgebraicSigmoid, GeometricMean, Sigmoid, SigmoidSqrt};
1013
use tg4_mixer::msg::{MixerFunctionResponse, QueryMsg};
1114

15+
fn mock_instance_on_tgrade(wasm: &[u8]) -> Instance<MockApi, MockStorage, MockQuerier> {
16+
mock_instance_with_options(
17+
wasm,
18+
MockInstanceOptions {
19+
supported_features: features_from_csv("iterator,tgrade"),
20+
gas_limit: 100_000_000_000_000,
21+
..Default::default()
22+
},
23+
)
24+
}
25+
1226
// Output of cargo wasm
1327
static WASM: &[u8] =
1428
include_bytes!("../../../target/wasm32-unknown-unknown/release/tg4_mixer.wasm");
@@ -24,7 +38,7 @@ fn main() {
2438
const STAKE: u64 = 100000;
2539
const ENGAGEMENT: u64 = 5000;
2640

27-
let mut deps = mock_instance(WASM, &[]);
41+
let mut deps = mock_instance_on_tgrade(WASM);
2842

2943
let max_points = Uint64::new(MAX_POINTS);
3044
let a = Decimal::from_ratio(37u128, 10u128);
@@ -34,12 +48,12 @@ fn main() {
3448

3549
println!();
3650
for (poe_fn_name, poe_fn, result, gas) in [
37-
("GeometricMean", GeometricMean {}, 22360, 5893350000),
51+
("GeometricMean", GeometricMean {}, 22360, 5900100000),
3852
(
3953
"Sigmoid",
4054
Sigmoid { max_points, p, s },
4155
MAX_POINTS,
42-
91848300000,
56+
89959950000,
4357
),
4458
(
4559
"SigmoidSqrt",
@@ -48,7 +62,7 @@ fn main() {
4862
s: s_sqrt,
4963
},
5064
997,
51-
21120000000,
65+
20597550000,
5266
),
5367
(
5468
"AlgebraicSigmoid",
@@ -59,7 +73,7 @@ fn main() {
5973
s,
6074
},
6175
996,
62-
86607900000,
76+
85284750000,
6377
),
6478
] {
6579
let benchmark_msg = QueryMsg::MixerFunction {

0 commit comments

Comments
 (0)