Created
December 6, 2019 23:17
-
-
Save timetocode/cfff514ed5a75546eeb119e17bc3f5f9 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
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