forked from model-checking/kani
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
06e0564
commit b504445
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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,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] |
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 @@ | ||
Complete - 0 successfully verified harnesses, 2 failures, 2 total. |
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,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() {} |