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.

real.cpp 2.3 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // Lol Engine — Benchmark program
  3. //
  4. // Copyright © 2005—2020 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. #include <lol/msg>
  18. #include <lol/real>
  19. using namespace lol;
  20. static size_t const REAL_TABLE_SIZE = 10000;
  21. static size_t const REAL_RUNS = 50;
  22. void bench_real(int mode)
  23. {
  24. float result[12] = { 0.0f };
  25. lol::timer timer;
  26. for (size_t run = 0; run < REAL_RUNS; run++)
  27. {
  28. switch (mode)
  29. {
  30. case 1:
  31. break;
  32. }
  33. real fib1 = 1.0, fib2 = 1.0;
  34. timer.get();
  35. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  36. {
  37. real tmp = fib1 + fib2;
  38. fib1 = fib2;
  39. fib2 = tmp;
  40. }
  41. result[0] += timer.get();
  42. real fact = 1.0;
  43. timer.get();
  44. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  45. fact = fact * real(1.0 + i);
  46. result[1] += timer.get();
  47. real invfact = 1.0;
  48. timer.get();
  49. for (size_t i = 0; i < REAL_TABLE_SIZE; i++)
  50. invfact = invfact / real(1.0 + i);
  51. result[2] += timer.get();
  52. timer.get();
  53. for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
  54. (void)sin(real(0.01 * i));
  55. result[3] += timer.get() * 128;
  56. timer.get();
  57. for (size_t i = 0; i < REAL_TABLE_SIZE / 128; i++)
  58. (void)exp((real)(int)(i - REAL_TABLE_SIZE / 256));
  59. result[4] += timer.get() * 128;
  60. }
  61. for (size_t i = 0; i < sizeof(result) / sizeof(*result); i++)
  62. result[i] *= 1e9f / (REAL_TABLE_SIZE * REAL_RUNS);
  63. msg::info(" ns/elem\n");
  64. msg::info("real = real + real %7.3f\n", result[0]);
  65. msg::info("real = real * real %7.3f\n", result[1]);
  66. msg::info("real = real / real %7.3f\n", result[2]);
  67. msg::info("real = sin(real) %7.3f\n", result[3]);
  68. msg::info("real = exp(real) %7.3f\n", result[4]);
  69. }