-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extend wastime demo to support wasi32-wasi
To support wasi, the PR start to the "wasi_snapshot_preview1". Cuurently, only the basic functions are supported, which are needed to run the fibonacci example. In addition, the fibonacci example is converted from a library to a common application.
- Loading branch information
Showing
8 changed files
with
281 additions
and
123 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
This file was deleted.
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,44 @@ | ||
use std::hint::black_box; | ||
use std::time::Instant; | ||
|
||
#[cfg(target_os = "hermit")] | ||
use hermit as _; | ||
|
||
// Number of iteration to stress the benchmark | ||
const N: u64 = 1000000; | ||
|
||
// Calculating fibonacci numbers | ||
fn fibonacci(n: u64) -> u64 { | ||
let mut fib: u64 = 1; | ||
let mut fib1: u64 = 1; | ||
let mut fib2: u64 = 1; | ||
|
||
for _ in 3..=n { | ||
fib = fib1 + fib2; | ||
fib1 = fib2; | ||
fib2 = fib; | ||
} | ||
|
||
fib | ||
} | ||
|
||
pub fn main() { | ||
println!("Call function fibonacci"); | ||
let result = fibonacci(30); | ||
println!("fibonacci(30) = {}", result); | ||
assert!( | ||
result == 832040, | ||
"Error in the calculation of fibonacci(30) " | ||
); | ||
|
||
let now = Instant::now(); | ||
for _ in 0..N { | ||
black_box(fibonacci(black_box(30))); | ||
} | ||
let elapsed = now.elapsed(); | ||
println!( | ||
"Time to call {} times native_fibonacci(30): {} s", | ||
N, | ||
elapsed.as_secs_f32() | ||
); | ||
} |
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
Oops, something went wrong.