From 624232f38b55cbc8aa008af2b9009f4b2a15a7d7 Mon Sep 17 00:00:00 2001 From: Wolfgang Thaller Date: Tue, 10 Apr 2012 23:55:53 +0200 Subject: [PATCH] benchmark for fixed --- Raytracer/CMakeLists.txt | 9 +++- Raytracer/fixedbenchmark.cc | 103 ++++++++++++++++++++++++++++++++++++ 2 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 Raytracer/fixedbenchmark.cc diff --git a/Raytracer/CMakeLists.txt b/Raytracer/CMakeLists.txt index 938741b3ad..eb06b323de 100644 --- a/Raytracer/CMakeLists.txt +++ b/Raytracer/CMakeLists.txt @@ -14,11 +14,18 @@ add_executable(Raytracer2 MACOSX_BUNDLE fixed.cc ) - if(APPLE) target_link_libraries(Raytracer "-framework Carbon") target_link_libraries(Raytracer2 "-framework Carbon") else() +add_executable(FixedBenchmark fixedbenchmark.cc ../App2/Console.cc ../App2/Console.h fixed.h fixed.cc) +target_link_libraries(FixedBenchmark retrocrt) +add_custom_command( + OUTPUT FixedBenchmark.bin + COMMAND ${MAKE_APPL} -c FixedBenchmark -o FixedBenchmark + DEPENDS FixedBenchmark) +add_custom_target(FixedBenchmarkAPPL ALL DEPENDS FixedBenchmark.bin) + target_link_libraries(Raytracer retrocrt) add_custom_command( OUTPUT Raytracer.bin diff --git a/Raytracer/fixedbenchmark.cc b/Raytracer/fixedbenchmark.cc new file mode 100644 index 0000000000..4e1d6b5301 --- /dev/null +++ b/Raytracer/fixedbenchmark.cc @@ -0,0 +1,103 @@ +#include +#include +#include + + +#include +#include +#include +#include +#include + +#include "MacUtils.h" +#include "Console.h" + +QDGlobals qd; + +extern ssize_t (*__write_hook)(int fd, const void*buf, size_t count); + +extern "C" ssize_t consolewrite(int fd, const void *buf, size_t count) +{ + const char *p = (const char*)buf; + for(int i = 0; i < count; i++) + Console::currentInstance->putch(*p++); + return count; +} + +#include "fixed.h" + +class timer +{ + long t; +public: + timer() : t(TickCount()) {} + float elapsed() { return (TickCount() - t) / 60.15f; } +}; +int main(int argc, char** argv) +{ + //GrafPort port; + WindowPtr win; + InitGraf(&qd.thePort); + InitFonts(); + InitWindows(); + InitMenus(); + + Rect r; + SetRect(&r, qd.screenBits.bounds.left + 5, qd.screenBits.bounds.top + 45, qd.screenBits.bounds.right - 5, qd.screenBits.bounds.bottom -5); + win = NewWindow(NULL, &r, PSTR("Retro68 Console"), true, 0, (WindowPtr)-1, false, 0); + + SetPort(win); + EraseRect(&win->portRect); + new char[32]; + Console console(win, win->portRect); + __write_hook = &consolewrite; + + std::cout << "Hello, world.\n"; + + std::cout << "Generating numbers..." << std::flush; + + const int n = 1000; + std::vector numbers(n); + for(int i = 0; i < numbers.size(); i++) + numbers[i] = fixed(std::rand(), fixed::raw()); + std::vector outputs(n); + + + std::cout << "done.\n"; + + std::cout << "Testing Multiplication..." << std::flush; + { + timer t; + for(int i = 0; i < n; i++) + { + outputs[i] = numbers[i] * numbers[n - i - 1]; + } + std::cout << 1000 * t.elapsed() / n << "ms\n"; + } + + std::cout << "Testing Division..." << std::flush; + { + timer t; + for(int i = 0; i < n; i++) + { + outputs[i] = numbers[i] / numbers[n - i - 1]; + } + std::cout << 1000 * t.elapsed() / n << "ms\n"; + } + + std::cout << "Testing Square Root..." << std::flush; + { + timer t; + for(int i = 0; i < n; i++) + { + outputs[i] = sqrt(numbers[i]); + } + std::cout << 1000 * t.elapsed() / n << "ms\n"; + } + + std::cout << "Press Enter to Exit ;-)\n"; + + console.ReadLine(); + + return 0; +}