/*
	Copyright 2016, 2017 Michele "King_DuckZ" Santullo

	This file is part of MyCurry.

	MyCurry 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.

	MyCurry 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.

	You should have received a copy of the GNU General Public License
	along with MyCurry.  If not, see <http://www.gnu.org/licenses/>.
*/

#include "fsgn_timing.hpp"
#include "fsgn.hpp"
#if defined(FSGN_WITH_TIMING)
#	include <chrono>
#	include <random>
#	include <vector>
#	include <algorithm>
#	include <iostream>
#endif

namespace curry {
#if defined(FSGN_WITH_TIMING)
	void do_fsgn_timing() {
		constexpr const auto count = 1000000U;
		std::minstd_rand rand;
		std::vector<float> inputs(count);
		std::generate(inputs.begin(), inputs.end(), [&](){
			return static_cast<float>(rand()) - static_cast<float>(rand.max()) / 2.0f;
		});

		//fast_fsgn
		{
			float result = 0.0f;

			auto t_start = std::chrono::high_resolution_clock::now();
			for (auto z = 0U; z < count; ++z) {
				result += fast_fsgn(inputs[z]);
			}
			auto t_end = std::chrono::high_resolution_clock::now();

			std::cout << "fast_fsgn result: " << result << " in " <<
				std::chrono::duration<double>(t_end - t_start).count() << '\n';
		}

		//fsgn_asm
		{
			float result = 0.0f;

			auto t_start = std::chrono::high_resolution_clock::now();
			for (auto z = 0U; z < count; ++z) {
				result += fsgn_asm(inputs[z]);
			}
			auto t_end = std::chrono::high_resolution_clock::now();

			std::cout << "fsgn_asm result: " << result << " in " <<
				std::chrono::duration<double>(t_end - t_start).count() << '\n';
		}

		//fsgn
		{
			float result = 0.0f;

			auto t_start = std::chrono::high_resolution_clock::now();
			for (auto z = 0U; z < count; ++z) {
				result += fsgn(inputs[z]);
			}
			auto t_end = std::chrono::high_resolution_clock::now();

			std::cout << "fsgn result: " << result << " in " <<
				std::chrono::duration<double>(t_end - t_start).count() << '\n';
		}
	}
#endif
} //namespace curry
