You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

91 line
2.4 KiB

  1. //
  2. // Lol Engine — Benchmark program
  3. //
  4. // Copyright: © 2005—2015 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // This program is free software; you can redistribute it and/or
  7. // modify it under the terms of the Do What The Fuck You Want To
  8. // Public License, Version 2, as published by Sam Hocevar. See
  9. // http://www.wtfpl.net/ for more details.
  10. //
  11. #if HAVE_CONFIG_H
  12. # include "config.h"
  13. #endif
  14. #include <cstdio>
  15. #include <lol/engine.h>
  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. msg::info(" ns/elem\n");
  68. msg::info("mat4 = mat4 %7.3f\n", result[0]);
  69. msg::info("float = mat4.det() %7.3f\n", result[1]);
  70. msg::info("mat4 *= mat4 %7.3f\n", result[2]);
  71. msg::info("mat4 += mat4 %7.3f\n", result[3]);
  72. msg::info("mat4 = mat4.invert() %7.3f\n", result[4]);
  73. }