No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

vector.cpp 2.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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] = RandF(-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. }