Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
data locality - slow example
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//https://www.youtube.com/watch?v=TJHgp1ugKGM //g++ 5.4.0 #include <iostream> #include <vector> class AIComponent { public: void update() { /* Work with and modify state... */ } private: // Goals, mood, etc. ... }; class PhysicsComponent { public: void update() { /* Work with and modify state... */ } private: // Rigid body, velocity, mass, etc. ... }; class RenderComponent { public: void render() { /* Work with and modify state... */ } private: // Mesh, textures, shaders, etc. ... }; class GameEntity { public: GameEntity(AIComponent* ai, PhysicsComponent* physics, RenderComponent* render) : ai_(ai), physics_(physics), render_(render) {} AIComponent* ai() { return ai_; } PhysicsComponent* physics() { return physics_; } RenderComponent* render() { return render_; } private: AIComponent* ai_; PhysicsComponent* physics_; RenderComponent* render_; }; int main() { std::vector<GameEntity> entities; int total = 10000000; for(int i=0; i<total; i++) { auto ge = GameEntity(new AIComponent(), new PhysicsComponent(), new RenderComponent()); entities.push_back(ge); } for(auto& e: entities) { e.ai()->update(); } for(auto& e: entities) { e.physics()->update(); } for(auto& e: entities) { e.render()->render(); } }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.42 sec, absolute running time: 1.84 sec, cpu time: 1.71 sec, memory peak: 1153 Mb, absolute service time: 2,27 sec
edit mode
|
history
|
discussion