Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

91 строка
2.5 KiB

  1. //
  2. // Lol Engine - Benchmark program
  3. //
  4. // Copyright: (c) 2005-2011 Sam Hocevar <sam@hocevar.net>
  5. // This program is free software; you can redistribute it and/or
  6. // modify it under the terms of the Do What The Fuck You Want To
  7. // Public License, Version 2, as published by Sam Hocevar. See
  8. // http://sam.zoy.org/projects/COPYING.WTFPL for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdio>
  14. #include "core.h"
  15. using namespace std;
  16. using namespace lol;
  17. static size_t const MATRIX_TABLE_SIZE = 64 * 1024;
  18. static size_t const MATRIX_RUNS = 100;
  19. void bench_matrix(int mode)
  20. {
  21. float result[5] = { 0.0f };
  22. Timer timer;
  23. /* Set up tables */
  24. mat4 *pm = new mat4[MATRIX_TABLE_SIZE + 1];
  25. float *pf = new float[MATRIX_TABLE_SIZE];
  26. for (size_t run = 0; run < MATRIX_RUNS; run++)
  27. {
  28. switch (mode)
  29. {
  30. case 1:
  31. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  32. for (int j = 0; j < 4; j++)
  33. for (int k = 0; k < 4; k++)
  34. pm[i][j][k] = RandF(-2.0f, 2.0f);
  35. break;
  36. }
  37. /* Copy matrices */
  38. timer.GetMs();
  39. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  40. pm[i] = pm[i + 1];
  41. result[0] += timer.GetMs();
  42. /* Determinant */
  43. timer.GetMs();
  44. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  45. pf[i] = pm[i].det();
  46. result[1] += timer.GetMs();
  47. /* Multiply matrices */
  48. timer.GetMs();
  49. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  50. pm[i] *= pm[i + 1];
  51. result[2] += timer.GetMs();
  52. /* Add matrices */
  53. timer.GetMs();
  54. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  55. pm[i] += pm[i + 1];
  56. result[3] += timer.GetMs();
  57. /* Invert matrix */
  58. timer.GetMs();
  59. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  60. pm[i] = pm[i].invert();
  61. result[4] += timer.GetMs();
  62. }
  63. delete[] pm;
  64. delete[] pf;
  65. for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
  66. result[i] *= 1000000.0f / (MATRIX_TABLE_SIZE * MATRIX_RUNS);
  67. Log::Info(" ns/elem\n");
  68. Log::Info("mat4 = mat4 %7.3f\n", result[0]);
  69. Log::Info("float = mat4.det() %7.3f\n", result[1]);
  70. Log::Info("mat4 *= mat4 %7.3f\n", result[2]);
  71. Log::Info("mat4 += mat4 %7.3f\n", result[3]);
  72. Log::Info("mat4 = mat4.invert() %7.3f\n", result[4]);
  73. }