Skip to content

Instantly share code, notes, and snippets.

@Deco
Created Mar 10, 2017
Embed
What would you like to do?
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