Скачиваний:
2
Добавлен:
15.08.2023
Размер:
2.14 Кб
Скачать
#ifndef iostream
#include <iostream>
#endif // !iostream

#include <sstream>
#include <vector>
#include <chrono>

#include "tString.h"

#ifndef FIRST_TRY
#define FIRST_TRY
#endif

double mean(std::vector<std::chrono::duration<double>> arr)
{
	double z = 0;

	for (size_t i{}; i < arr.size(); i++)
	{
		z += arr[i].count();
	}

	return z / arr.size();
}

std::vector<std::string> dict(tString str)
{
	std::stringstream line(str.cstr());
	std::string segment;
	std::vector<std::string> seglist;

	while (std::getline(line, segment, ' '))
	{
		seglist.push_back(segment.c_str());
	}

	return seglist;
}

#ifdef FIRST_TRY

int main(_In_ int argc, _In_ char* argv[])
{
	std::ofstream OutDir, OutBrut;

	std::chrono::system_clock::time_point beg;
	std::chrono::system_clock::time_point end;
	std::chrono::duration<double> sec;

	std::vector<std::chrono::duration<double>> timeArrayA;
	std::vector<std::chrono::duration<double>> timeArrayB;
	std::vector<std::string> dictianary;

	OutDir.open("OutDir.txt");
	OutBrut.open("OutBrut.txt");

	int counter = 1;

	for (size_t i = 100; i < 1000; i+=100)
	{
		std::string tmp = std::to_string(i) + "wordText.txt";
		std::ifstream file(tmp);

		tString a(file);

		dictianary = dict(a);

		const char* word = dictianary[rand() % dictianary.size()].c_str();

		std::cout << word << std::endl;

		for (size_t j{}; j < 10000; j++)
		{
			beg = std::chrono::system_clock::now();
			a.DirectSearch(word, 0);
			end = std::chrono::system_clock::now();
			sec = end - beg;
			timeArrayA.push_back(sec);

			beg = std::chrono::system_clock::now();
			a.BrootForce(word, 0);
			end = std::chrono::system_clock::now();
			sec = end - beg;
			timeArrayB.push_back(sec);
		}

		OutDir << a.len() << "\t" << mean(timeArrayA) << "\n";
		OutBrut << a.len() << "\t" << mean(timeArrayB) << "\n";

		timeArrayA.clear();
		timeArrayB.clear();

		std::cout << "End of iteration " << i / 100 << std::endl;
	}
}

#else

void randomChar();

int main(_In_ int argc, _In_ char* argv[])
{
	
	return 0;
}

#endif // !TSTRING
Соседние файлы в папке 2