Skip to content

Instantly share code, notes, and snippets.

@Deco
Created March 10, 2017 15:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Deco/de0496df5689423e9747b8e85034cc7f to your computer and use it in GitHub Desktop.
Save Deco/de0496df5689423e9747b8e85034cc7f to your computer and use it in GitHub Desktop.
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