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: © 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 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.Get();
  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.Get();
  39. real fact = 1.0;
  40. timer.Get();
  41. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  42. fact = fact * real(1.0 + i);
  43. result[1] += timer.Get();
  44. real invfact = 1.0;
  45. timer.Get();
  46. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  47. invfact = invfact / real(1.0 + i);
  48. result[2] += timer.Get();
  49. timer.Get();
  50. for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
  51. sin(real(0.01 * i));
  52. result[3] += timer.Get() * 128;
  53. timer.Get();
  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.Get() * 128;
  57. }
  58. for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
  59. result[i] *= 1e9f / (REAL_TABLE_SIZE * REAL_RUNS);
  60. msg::info(" ns/elem\n");
  61. msg::info("real = real + real %7.3f\n", result[0]);
  62. msg::info("real = real * real %7.3f\n", result[1]);
  63. msg::info("real = real / real %7.3f\n", result[2]);
  64. msg::info("real = sin(real) %7.3f\n", result[3]);
  65. msg::info("real = exp(real) %7.3f\n", result[4]);
  66. }