Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // Lol Engine — Benchmark program
  3. //
  4. // Copyright © 2005—2015 Sam Hocevar <sam@hocevar.net>
  5. //
  6. // This program is free software. It comes without any warranty, to
  7. // the extent permitted by applicable law. You can redistribute it
  8. // and/or modify it under the terms of the Do What the Fuck You Want
  9. // to Public License, Version 2, as published by the WTFPL Task Force.
  10. // See http://www.wtfpl.net/ for more details.
  11. //
  12. #if HAVE_CONFIG_H
  13. # include "config.h"
  14. #endif
  15. #include <cstdio>
  16. #include <lol/engine.h>
  17. using namespace lol;
  18. static size_t const REAL_TABLE_SIZE = 10000;
  19. static size_t const REAL_RUNS = 50;
  20. void bench_real(int mode)
  21. {
  22. float result[12] = { 0.0f };
  23. Timer timer;
  24. for (size_t run = 0; run < REAL_RUNS; run++)
  25. {
  26. switch (mode)
  27. {
  28. case 1:
  29. break;
  30. }
  31. real fib1 = 1.0, fib2 = 1.0;
  32. timer.Get();
  33. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  34. {
  35. real tmp = fib1 + fib2;
  36. fib1 = fib2;
  37. fib2 = tmp;
  38. }
  39. result[0] += timer.Get();
  40. real fact = 1.0;
  41. timer.Get();
  42. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  43. fact = fact * real(1.0 + i);
  44. result[1] += timer.Get();
  45. real invfact = 1.0;
  46. timer.Get();
  47. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  48. invfact = invfact / real(1.0 + i);
  49. result[2] += timer.Get();
  50. timer.Get();
  51. for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
  52. sin(real(0.01 * i));
  53. result[3] += timer.Get() * 128;
  54. timer.Get();
  55. for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
  56. exp((real)(int)(i - REAL_TABLE_SIZE / 256));
  57. result[4] += timer.Get() * 128;
  58. }
  59. for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
  60. result[i] *= 1e9f / (REAL_TABLE_SIZE * REAL_RUNS);
  61. msg::info(" ns/elem\n");
  62. msg::info("real = real + real %7.3f\n", result[0]);
  63. msg::info("real = real * real %7.3f\n", result[1]);
  64. msg::info("real = real / real %7.3f\n", result[2]);
  65. msg::info("real = sin(real) %7.3f\n", result[3]);
  66. msg::info("real = exp(real) %7.3f\n", result[4]);
  67. }