Guest User

Untitled

a guest
Jan 6th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. const size_t ArraySize = 1000;
  2.  
  3. class Ball
  4. {
  5. public:
  6. float x,y,z;
  7. Ball():
  8. x(0),
  9. y(0),
  10. z(0)
  11. {
  12. }
  13.  
  14. void Update()
  15. {
  16. x += 5;
  17. y += 5;
  18. z += 5;
  19. }
  20. };
  21.  
  22. std::vector<Ball> g_balls(ArraySize);
  23.  
  24. class Balls
  25. {
  26. public:
  27. std::vector<float> x;
  28. std::vector<float> y;
  29. std::vector<float> z;
  30.  
  31. Balls():
  32. x(ArraySize,0),
  33. y(ArraySize,0),
  34. z(ArraySize,0)
  35. {
  36. }
  37.  
  38. void Update()
  39. {
  40. const size_t num = x.size();
  41. if(num == 0)
  42. {
  43. return;
  44. }
  45.  
  46. const float* lastX = &x[num - 1];
  47.  
  48. float* pX = &x[0];
  49. float* pY = &y[0];
  50. float* pZ = &z[0];
  51. for( ; pX <= lastX; ++pX, ++pY, ++pZ)
  52. {
  53. *pX += 5;
  54. *pY += 5;
  55. *pZ += 5;
  56. }
  57. }
  58. };
  59.  
  60. int main()
  61. {
  62. Balls balls;
  63.  
  64. Timer time1;
  65. time1.Start();
  66. balls.Update();
  67. time1.Stop();
  68.  
  69. Timer time2;
  70. time2.Start();
  71. const size_t arrSize = g_balls.size();
  72. if(arrSize > 0)
  73. {
  74. const Ball* lastBall = &g_balls[arrSize - 1];
  75. Ball* pBall = &g_balls[0];
  76. for( ; pBall <= lastBall; ++pBall)
  77. {
  78. pBall->Update();
  79. }
  80. }
  81. time2.Stop();
  82.  
  83.  
  84. printf("Data Oriented design time: %fn",time1.Get_Microseconds());
  85. printf("OOB oriented design time: %fn",time2.Get_Microseconds());
  86.  
  87. return 0;
  88. }
  89.  
  90. const float* lastX = &x[num - 1];//remember, x is a std::vector of floats
  91.  
  92. float* pX = &x[0];//remember, x is a std::vector of floats
  93. float* pY = &y[0];//remember, y is a std::vector of floats
  94. float* pZ = &z[0];//remember, z is a std::vector of floats
  95. for( ; pX <= lastX; ++pX, ++pY, ++pZ)
  96. {
  97. *pX += 5;
  98. *pY += 5;
  99. *pZ += 5;
  100. }
  101.  
  102. class IPixel
  103. {
  104. public:
  105. virtual ~IPixel() {}
  106. ...
  107. };
  108.  
  109. class IImage
  110. {
  111. public:
  112. virtual ~IImage() {}
  113. ...
  114. };
Add Comment
Please, Sign In to add comment