25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

91 satır
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://www.wtfpl.net/ 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] = rand(-2.0f, 2.0f);
  35. break;
  36. }
  37. /* Copy matrices */
  38. timer.Get();
  39. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  40. pm[i] = pm[i + 1];
  41. result[0] += timer.Get();
  42. /* Determinant */
  43. timer.Get();
  44. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  45. pf[i] = determinant(pm[i]);
  46. result[1] += timer.Get();
  47. /* Multiply matrices */
  48. timer.Get();
  49. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  50. pm[i] *= pm[i + 1];
  51. result[2] += timer.Get();
  52. /* Add matrices */
  53. timer.Get();
  54. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  55. pm[i] += pm[i + 1];
  56. result[3] += timer.Get();
  57. /* Invert matrix */
  58. timer.Get();
  59. for (size_t i = 0; i < MATRIX_TABLE_SIZE; i++)
  60. pm[i] = inverse(pm[i]);
  61. result[4] += timer.Get();
  62. }
  63. delete[] pm;
  64. delete[] pf;
  65. for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
  66. result[i] *= 1e9f / (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. }