Skip to content

Commit

Permalink
Add test for model-checking#1823
Browse files Browse the repository at this point in the history
  • Loading branch information
zhassan-aws committed Dec 8, 2022
1 parent 06e0564 commit b504445
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/perf/misc/array_fold/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT

[package]
name = "array_fold"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
1 change: 1 addition & 0 deletions tests/perf/misc/array_fold/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Complete - 0 successfully verified harnesses, 2 failures, 2 total.
34 changes: 34 additions & 0 deletions tests/perf/misc/array_fold/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT

//! This test checks the performance of fold, which uses iterators under the
//! hood.
//! The test is from https://github.com/model-checking/kani/issues/1823.
//! Pre CBMC 5.72.0, it took ~36 seconds and consumed ~3.6 GB of memory.
//! With CBMC 5.72.0, it takes ~11 seconds and consumes ~255 MB of memory.
pub fn array_sum_fold(x : [usize; 100]) -> usize {
x.iter().fold(0, |accumulator, current| accumulator + current)
}

pub fn array_sum_for(x : [usize; 100]) -> usize {
let mut accumulator : usize = 0;
for i in 0..100 {
accumulator = x[i] + accumulator
}
accumulator
}

#[kani::proof]
fn array_sum_fold_proof() {
let x: [usize; 100] = kani::any();
array_sum_fold(x);
}

#[kani::proof]
fn array_sum_for_proof() {
let x: [usize; 100] = kani::any();
array_sum_for(x);
}

fn main() {}

0 comments on commit b504445

Please sign in to comment.