Created
March 10, 2017 15:47
-
-
Save Deco/de0496df5689423e9747b8e85034cc7f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
extern crate time; | |
#[derive(Debug, Clone)] | |
struct Vertex { position: [f32; 2], velocity: [f32; 2] } | |
fn main() { | |
let mut arr = vec![ Vertex { position: [0.0, 0.0], velocity: [0.0, 0.0] }; 200000 ]; | |
for (_, v) in arr.iter_mut().enumerate() { | |
// v.position = [0.0, 0.0]; | |
v.position = [0.0, 0.0]; | |
v.velocity = [0.0, 0.0]; | |
} | |
for n in 0..10 { | |
let t0 = time_milliseconds(); | |
for i in 0..arr.len() { | |
arr[i].position[0] = t0 as f32 % 1.0; | |
} | |
let t1 = time_milliseconds(); | |
println!("{:?}: {:?}", n, t1-t0); | |
} | |
} | |
fn time_milliseconds() -> f64 { | |
let timespec = time::get_time(); | |
let milliseconds: f64 = (timespec.sec as f64 * 1000.0) + (timespec.nsec as f64 / 1000.0 / 1000.0); | |
milliseconds | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment