Skip to content

Instantly share code, notes, and snippets.

@timetocode
Created December 6, 2019 23:17
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 timetocode/cfff514ed5a75546eeb119e17bc3f5f9 to your computer and use it in GitHub Desktop.
Save timetocode/cfff514ed5a75546eeb119e17bc3f5f9 to your computer and use it in GitHub Desktop.
use std::time::Instant;
#[derive(Debug)]
struct Entity {
nid: u32,
x: f64,
y: f64,
hp: u8,
name: String
}
fn create_entity(nid: u32, x: f64, y: f64, name: String) -> Entity {
Entity {
nid,
x,
y,
hp: 100,
name
}
}
fn main() {
let mut entities: Vec<Entity> = Vec::new();
for nid in 1..500000 {
entities.push(create_entity(nid, 50.0, 50.0, String::from("entity") + &nid.to_string()));
}
let start = Instant::now();
for entity in entities.iter_mut() {
entity.x += 5.0;
entity.y += 5.0;
}
println!("took {:?}", Instant::now() - start);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment