Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

real.cpp 2.2 KiB

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