2012-04-24 01:22:36 +00:00
|
|
|
/*
|
2014-09-17 01:35:18 +00:00
|
|
|
Copyright 2014 Wolfgang Thaller.
|
2012-04-24 01:22:36 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
This file is part of Retro68.
|
2012-04-24 01:22:36 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
Retro68 is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
2012-04-24 01:22:36 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
Retro68 is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
2012-04-24 01:22:36 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Retro68. If not, see <http://www.gnu.org/licenses/>.
|
2012-04-24 01:22:36 +00:00
|
|
|
*/
|
|
|
|
|
2012-04-10 21:55:53 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include <cstdlib>
|
|
|
|
#include <cstdio>
|
2014-09-17 01:35:18 +00:00
|
|
|
#include <vector>
|
2012-04-10 21:55:53 +00:00
|
|
|
|
|
|
|
#include <Events.h>
|
|
|
|
|
2014-09-23 21:48:41 +00:00
|
|
|
#include "fixed.h"
|
2014-09-17 01:35:18 +00:00
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
using std::sqrt;
|
2012-04-10 21:55:53 +00:00
|
|
|
|
|
|
|
class timer
|
|
|
|
{
|
|
|
|
long t;
|
|
|
|
public:
|
|
|
|
timer() : t(TickCount()) {}
|
|
|
|
float elapsed() { return (TickCount() - t) / 60.15f; }
|
|
|
|
};
|
2014-09-17 01:35:18 +00:00
|
|
|
|
|
|
|
template<class number>
|
|
|
|
void runTests(std::string type, std::vector<number>& numbers)
|
2012-04-10 21:55:53 +00:00
|
|
|
{
|
2014-09-17 01:35:18 +00:00
|
|
|
std::cout << "***********************************\n";
|
|
|
|
std::cout << "Running tests on type " << type << ":\n";
|
|
|
|
std::cout << "***********************************\n";
|
|
|
|
|
|
|
|
int n = numbers.size();
|
2014-09-23 21:48:41 +00:00
|
|
|
std::vector<number> outputs(n);
|
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
std::cout << "Testing Multiplication..." << std::flush;
|
|
|
|
{
|
|
|
|
timer t;
|
2014-09-23 21:48:41 +00:00
|
|
|
for(int i = 0; i < n; i++)
|
2014-09-14 22:43:30 +00:00
|
|
|
{
|
|
|
|
outputs[i] = numbers[i] * numbers[n - i - 1];
|
2014-09-23 21:48:41 +00:00
|
|
|
}
|
2014-09-14 22:43:30 +00:00
|
|
|
std::cout << 1000 * t.elapsed() / n << "ms\n";
|
|
|
|
}
|
2014-09-23 21:48:41 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
std::cout << "Testing Division..." << std::flush;
|
|
|
|
{
|
|
|
|
timer t;
|
2014-09-23 21:48:41 +00:00
|
|
|
for(int i = 0; i < n; i++)
|
2014-09-14 22:43:30 +00:00
|
|
|
{
|
|
|
|
outputs[i] = numbers[i] / numbers[n - i - 1];
|
2014-09-23 21:48:41 +00:00
|
|
|
}
|
2014-09-14 22:43:30 +00:00
|
|
|
std::cout << 1000 * t.elapsed() / n << "ms\n";
|
|
|
|
}
|
2014-09-23 21:48:41 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
std::cout << "Testing Square Root..." << std::flush;
|
|
|
|
{
|
|
|
|
timer t;
|
2014-09-23 21:48:41 +00:00
|
|
|
for(int i = 0; i < n; i++)
|
2014-09-14 22:43:30 +00:00
|
|
|
{
|
|
|
|
outputs[i] = sqrt(numbers[i]);
|
2014-09-23 21:48:41 +00:00
|
|
|
}
|
2014-09-14 22:43:30 +00:00
|
|
|
std::cout << 1000 * t.elapsed() / n << "ms\n";
|
|
|
|
}
|
2014-09-23 21:48:41 +00:00
|
|
|
std::cout << std::endl;
|
2014-09-17 01:35:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
std::cout << "Hello, world.\n";
|
|
|
|
|
|
|
|
std::cout << "Generating numbers..." << std::flush;
|
|
|
|
|
|
|
|
const int n = 1000;
|
2014-09-23 21:48:41 +00:00
|
|
|
std::vector<fixed> numbers(n);
|
2014-09-17 01:35:18 +00:00
|
|
|
std::vector<float> floats(n);
|
2014-09-23 21:48:41 +00:00
|
|
|
std::vector<double> doubles(n);
|
|
|
|
|
|
|
|
for(int i = 0; i < numbers.size(); i++)
|
2014-09-17 01:35:18 +00:00
|
|
|
{
|
2014-09-23 21:48:41 +00:00
|
|
|
numbers[i] = fixed(std::rand(), fixed::raw());
|
2014-09-17 01:35:18 +00:00
|
|
|
floats[i] = float(std::rand()) / RAND_MAX;
|
2014-09-23 21:48:41 +00:00
|
|
|
doubles[i] = double(std::rand()) / RAND_MAX;
|
|
|
|
}
|
|
|
|
std::vector<fixed> outputs(n);
|
2014-09-17 01:35:18 +00:00
|
|
|
std::cout << "done.\n\n";
|
|
|
|
|
|
|
|
runTests("float", floats);
|
2014-09-23 21:48:41 +00:00
|
|
|
runTests("double", doubles);
|
|
|
|
runTests("fixed", numbers);
|
2012-04-10 21:55:53 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
std::cout << "Press Enter to Exit ;-)\n";
|
|
|
|
|
2014-09-17 01:35:18 +00:00
|
|
|
std::cin.get();
|
2014-09-23 21:48:41 +00:00
|
|
|
|
2014-09-14 22:43:30 +00:00
|
|
|
return 0;
|
2012-04-10 21:55:53 +00:00
|
|
|
}
|