generated from stacks-network/.github
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for
(list ...)
and (fold ...)
Also adds a benchmark to track the speed.
- Loading branch information
Showing
9 changed files
with
320 additions
and
44 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
use clarity::{vm::{types::{QualifiedContractIdentifier, StandardPrincipalData}, ContractName, database::ClarityDatabase, costs::LimitedCostTracker, contexts::GlobalContext, ContractContext, ClarityVersion}, types::StacksEpochId, consts::CHAIN_ID_TESTNET}; | ||
use criterion::{criterion_group, criterion_main, Criterion}; | ||
use clar2wasm_tests::datastore::{Datastore, StacksConstants, BurnDatastore}; | ||
use clar2wasm_tests::util::WasmtimeHelper; | ||
|
||
fn fold_add(c: &mut Criterion) { | ||
c.bench_function("fold_add", |b| { | ||
let contract_id = QualifiedContractIdentifier::new( | ||
StandardPrincipalData::transient(), | ||
ContractName::from("fold-bench"), | ||
); | ||
let mut datastore = Datastore::new(); | ||
let constants = StacksConstants { | ||
burn_start_height: 0, | ||
pox_prepare_length: 0, | ||
pox_reward_cycle_length: 0, | ||
pox_rejection_fraction: 0, | ||
epoch_21_start_height: 0, | ||
}; | ||
let burn_datastore = BurnDatastore::new(constants); | ||
let mut conn = ClarityDatabase::new(&mut datastore, &burn_datastore, &burn_datastore); | ||
conn.begin(); | ||
conn.set_clarity_epoch_version(StacksEpochId::Epoch24); | ||
conn.commit(); | ||
let cost_tracker = LimitedCostTracker::new_free(); | ||
let mut global_context = GlobalContext::new( | ||
false, | ||
CHAIN_ID_TESTNET, | ||
conn, | ||
cost_tracker, | ||
StacksEpochId::Epoch24, | ||
); | ||
let mut contract_context = | ||
ContractContext::new(contract_id.clone(), ClarityVersion::Clarity2); | ||
|
||
global_context.begin(); | ||
{ | ||
let mut helper = | ||
WasmtimeHelper::new(contract_id, &mut global_context, &mut contract_context); | ||
|
||
b.iter(|| { | ||
helper.call_public_function("fold-add", &[]); | ||
}); | ||
} | ||
global_context.commit().unwrap(); | ||
}); | ||
} | ||
|
||
criterion_group!(all, fold_add); | ||
criterion_main!(all); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
(define-private (add (x int) (y int)) | ||
(+ x y) | ||
) | ||
|
||
(define-public (fold-add) | ||
(ok (fold add (list 1 2 3 4) 0)) | ||
) |
Oops, something went wrong.