Skip to content

Commit 9b311bd

Browse files
committed
Modified pi example to report benchmarked runtime
1 parent fb1b3cc commit 9b311bd

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

examples/pi.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use time::PreciseTime;
55
use af::Dim4;
66
use af::Aftype;
77

8+
#[allow(unused_must_use)]
9+
#[allow(unused_variables)]
810
fn main() {
911
af::set_device(0);
1012
af::info();
@@ -15,14 +17,17 @@ fn main() {
1517
let y = &af::randu(dims, Aftype::F32).unwrap();
1618

1719
let start = PreciseTime::now();
18-
let pi_val = af::add(&(x*x), &(y*y))
19-
//let pi_val = af::sqrt(&(x*x) + &(y*y))
20-
.and_then( |z| af::sqrt(&z) )
21-
.and_then( |z| af::le(&z, &af::constant(1, dims).unwrap()) )
22-
.and_then( |z| af::sum_all(&z) )
23-
.map( |z| z.0 * 4.0/(samples as f64) )
24-
.unwrap();
20+
21+
for bench_iter in 0..100 {
22+
let pi_val = af::add(&(x*x), &(y*y))
23+
.and_then( |z| af::sqrt(&z) )
24+
.and_then( |z| af::le(&z, &af::constant(1, dims).unwrap()) )
25+
.and_then( |z| af::sum_all(&z) )
26+
.map( |z| z.0 * 4.0/(samples as f64) )
27+
.unwrap();
28+
}
29+
2530
let end = PreciseTime::now();
2631

27-
println!("Estimated Pi Value: {} in {} seconds", pi_val, start.to(end));
32+
println!("Estimated Pi Value in {} seconds", start.to(end) / 100);
2833
}

0 commit comments

Comments
 (0)