Added black_box, currently unused; changed computation.

This commit is contained in:
Emery Berger 2022-08-13 15:33:03 -04:00
parent 76699e857b
commit 5e0cd59033

View File

@ -1,18 +1,39 @@
#[allow(unused)]
use coz;
use std::thread;
#[no_mangle]
pub fn a_first_fn() {
for _x in 0..2000000 {}
fn black_box<T>(dummy: T) -> T {
unsafe {
std::ptr::read_volatile(&dummy)
}
}
#[no_mangle]
pub fn b_second_fn() {
for _y in 0..1900000 {}
pub fn a_first_fn() -> i64 {
let mut v: i64 = 0;
for x in 0..200000000 {
v += x * x;
v -= x * x;
v += x * x;
v -= x * x;
}
return v;
}
#[no_mangle]
pub fn b_second_fn() -> i64 {
let mut v: i64 = 0;
for x in 0..100000000 {
v += x * x;
v -= x * x;
v += x * x;
v -= x * x;
}
return v;
}
fn main() {
for _n in 1..1000 {
for _n in 1..100 {
let handle1 = thread::spawn(|| a_first_fn());
let handle2 = thread::spawn(|| b_second_fn());
handle1.join().unwrap();