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.
 
 
 

82 rindas
2.2 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 REAL_TABLE_SIZE = 10000;
  18. static size_t const REAL_RUNS = 50;
  19. void bench_real(int mode)
  20. {
  21. float result[12] = { 0.0f };
  22. Timer timer;
  23. for (size_t run = 0; run < REAL_RUNS; run++)
  24. {
  25. switch (mode)
  26. {
  27. case 1:
  28. break;
  29. }
  30. real fib1 = 1.0, fib2 = 1.0;
  31. timer.GetMs();
  32. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  33. {
  34. real tmp = fib1 + fib2;
  35. fib1 = fib2;
  36. fib2 = tmp;
  37. }
  38. result[0] += timer.GetMs();
  39. real fact = 1.0;
  40. timer.GetMs();
  41. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  42. fact = fact * real(1.0 + i);
  43. result[1] += timer.GetMs();
  44. real invfact = 1.0;
  45. timer.GetMs();
  46. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  47. invfact = invfact / real(1.0 + i);
  48. result[2] += timer.GetMs();
  49. timer.GetMs();
  50. for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
  51. sin(real(0.01 * i));
  52. result[3] += timer.GetMs() * 128;
  53. timer.GetMs();
  54. for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
  55. exp((real)(int)(i - REAL_TABLE_SIZE / 256));
  56. result[4] += timer.GetMs() * 128;
  57. }
  58. for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
  59. result[i] *= 1000000.0f / (REAL_TABLE_SIZE * REAL_RUNS);
  60. Log::Info(" ns/elem\n");
  61. Log::Info("real = real + real %7.3f\n", result[0]);
  62. Log::Info("real = real * real %7.3f\n", result[1]);
  63. Log::Info("real = real / real %7.3f\n", result[2]);
  64. Log::Info("real = sin(real) %7.3f\n", result[3]);
  65. Log::Info("real = exp(real) %7.3f\n", result[4]);
  66. }