Created
May 9, 2018 16:01
-
-
Save alexcrichton/c05bc51c6771bba5ae5b57561a6c1cd3 to your computer and use it in GitHub Desktop.
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
#![feature(asm)] | |
use std::ptr; | |
fn black_box<T>(t: &T) { | |
unsafe { asm!("" : : "r"(t)); } | |
} | |
fn main() { | |
let mut x = Vec::<u8>::with_capacity(1024 * 1024 * 1024); | |
for _ in 0..10 { | |
black_box(&x); | |
black_box(&x.as_ptr()); | |
let a = x.as_ptr(); | |
let b = x.as_mut_ptr(); | |
black_box(&a); | |
black_box(&b); | |
let c = x.capacity(); | |
black_box(&c); | |
unsafe { | |
ptr::copy(a, b, c); | |
} | |
black_box(&x); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment