express_sample.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #include <chrono>
  2. #include <thread>
  3. #include <vector>
  4. #include <iostream>
  5. #include <condition_variable>
  6. #include <cstdlib>
  7. #include <math.h>
  8. #include <easy/profiler.h>
  9. #include <easy/reader.h>
  10. int OBJECTS = 500;
  11. void modellingThread(){
  12. EASY_THREAD("Modelling");
  13. static const int N = OBJECTS;
  14. volatile double *pos[N];
  15. for (int i = 0; i < N; ++i)
  16. {
  17. pos[i] = new volatile double[3];
  18. }
  19. {
  20. EASY_BLOCK("Collisions");
  21. volatile int i, j;
  22. volatile double dist;
  23. for (i = 0; i < N; ++i)
  24. {
  25. for (j = i + 1; j < N; ++j)
  26. {
  27. EASY_BLOCK("Check");
  28. volatile double v[3];
  29. v[0] = pos[i][0] - pos[j][0];
  30. v[1] = pos[i][1] - pos[j][1];
  31. v[2] = pos[i][2] - pos[j][2];
  32. dist = v[0] * v[0] + v[1] * v[1] + v[2] * v[2];
  33. if (dist < 10000)
  34. {
  35. dist *= dist;
  36. }
  37. }
  38. }
  39. }
  40. for (int i = 0; i < N; ++i)
  41. {
  42. delete [] pos[i];
  43. }
  44. }
  45. //////////////////////////////////////////////////////////////////////////
  46. int main(int argc, char* argv[])
  47. {
  48. if (argc > 1 && argv[1]){
  49. OBJECTS = std::atoi(argv[1]);
  50. }
  51. std::cout << "Objects count: " << OBJECTS << std::endl;
  52. auto start = std::chrono::system_clock::now();
  53. EASY_PROFILER_ENABLE;
  54. EASY_MAIN_THREAD;
  55. modellingThread();
  56. auto end = std::chrono::system_clock::now();
  57. auto elapsed =
  58. std::chrono::duration_cast<std::chrono::microseconds>(end - start);
  59. std::cout << "Elapsed time: " << elapsed.count() << " usec" << std::endl;
  60. auto blocks_count = profiler::dumpBlocksToFile("test.prof");
  61. std::cout << "Blocks count: " << blocks_count << std::endl;
  62. return 0;
  63. }