Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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://www.wtfpl.net/ for more details.
  9. //
  10. #if defined HAVE_CONFIG_H
  11. # include "config.h"
  12. #endif
  13. #include <cstdio>
  14. #include <lol/main.h>
  15. using namespace lol;
  16. static size_t const MATRIX_TABLE_SIZE = 64 * 1024;
  17. static size_t const MATRIX_RUNS = 100;
  18. void bench_matrix(int mode)
  19. {
  20. float result[5] = { 0.0f };
  21. Timer timer;
  22. /* Set up tables */
  23. mat4 *pm = new mat4[MATRIX_TABLE_SIZE + 1];
  24. float *pf = new float[MATRIX_TABLE_SIZE];
  25. for (size_t run = 0; run < MATRIX_RUNS; run++)
  26. {
  27. switch (mode)
  28. {
  29. case 1:
  30. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  31. for (int j = 0; j < 4; j++)
  32. for (int k = 0; k < 4; k++)
  33. pm[i][j][k] = rand(-2.0f, 2.0f);
  34. break;
  35. }
  36. /* Copy matrices */
  37. timer.Get();
  38. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  39. pm[i] = pm[i + 1];
  40. result[0] += timer.Get();
  41. /* Determinant */
  42. timer.Get();
  43. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  44. pf[i] = determinant(pm[i]);
  45. result[1] += timer.Get();
  46. /* Multiply matrices */
  47. timer.Get();
  48. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  49. pm[i] *= pm[i + 1];
  50. result[2] += timer.Get();
  51. /* Add matrices */
  52. timer.Get();
  53. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  54. pm[i] += pm[i + 1];
  55. result[3] += timer.Get();
  56. /* Invert matrix */
  57. timer.Get();
  58. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  59. pm[i] = inverse(pm[i]);
  60. result[4] += timer.Get();
  61. }
  62. delete[] pm;
  63. delete[] pf;
  64. for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
  65. result[i] *= 1e9f / (MATRIX_TABLE_SIZE * MATRIX_RUNS);
  66. Log::Info(" ns/elem\n");
  67. Log::Info("mat4 = mat4 %7.3f\n", result[0]);
  68. Log::Info("float = mat4.det() %7.3f\n", result[1]);
  69. Log::Info("mat4 *= mat4 %7.3f\n", result[2]);
  70. Log::Info("mat4 += mat4 %7.3f\n", result[3]);
  71. Log::Info("mat4 = mat4.invert() %7.3f\n", result[4]);
  72. }