Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Rust version that takes several seconds to execute based on the size of Ent:
- // Strangely runs fine on Playground but not from the executable generated by rustc on desktop
- struct Ent
- {
- x : i32,
- foo : [i32; 100000]
- }
- impl Ent
- {
- fn do_thing(&mut self)
- {
- self.x += 2;
- }
- }
- fn main()
- {
- let mut list : Vec<Ent> = Vec::new();
- for _ in 0..100
- {
- let entity = Ent { x : 0, foo : [0; 100000] };
- list.push(entity);
- }
- for _ in 0..4000000
- {
- for entity in &mut list
- {
- entity.do_thing();
- }
- }
- }
- // CPP version that executes instantaneously:
- /*
- #include <vector>
- struct Ent
- {
- int x;
- int foo[100000];
- Ent() : x(0), foo() {}
- void doThing()
- {
- x += 2;
- }
- };
- int main()
- {
- std::vector<Ent> list;
- for (int i = 0; i < 100; ++i)
- {
- Ent entity;
- list.push_back(entity);
- }
- for (int i = 0; i < 4000000; ++i)
- {
- for (auto iter = list.begin(); iter != list.end(); ++iter)
- {
- iter->doThing();
- }
- }
- return 0;
- }
- */
Add Comment
Please, Sign In to add comment