Esempio n. 1
0
int main(int argc, char ** argv)
{
    QApplication app(argc, argv);

   // TerminalWindow window;
  //  window.show();
   testContainer();
    return app.exec();
}
void Base::testContainers()
{
	logInfoSkim<<"<<<<< CONTAINERS TESTS >>>>>";

	Base::uint cyclesCount = 10000;
	Base::uint megaCyclesCount = 10;

#ifdef DEBUG
	cyclesCount /= 10;
	megaCyclesCount = 4;
#endif


	Base::uint* randArr = new Base::uint[cyclesCount];
	for(Base::uint i=0; i < cyclesCount; i++)
		randArr[i] = Base::rand(0,100000000);

	std::map<Base::uint, Base::uint> stdmap;
#ifdef _MSC_VER
	std::hash_map<Base::uint, Base::uint> stdhashmap;
#endif
	Base::RedBlackTreeMap< Base::Pair<Base::uint, Base::uint> > rbtmap;
	Base::HashTable< Base::Pair<Base::uint, Base::uint> > hashTable;
	Base::HashMap< Base::Pair<Base::uint, Base::uint> > hashMap;
	Base::HashArray< Base::Pair<Base::uint, Base::uint> > hashArray;
	Base::SortedArray< Base::Pair<Base::uint, Base::uint> > sortedArray;
	Base::RedBlackTreeMap< Base::Pair<Base::uint, Base::uint>, AllocatorWrapper<TCellDefragmentAllocator< Base::RedBlackTreeMapNodeT<Pair<Base::uint, Base::uint> >::Type > > > rbtmapCellAlloc;

	double insertTime;
	double eraseTime;
	double findTime;
	double iterationTime;
	Base::uint summ = 0;

	testStdContainer(stdmap, cyclesCount, megaCyclesCount, randArr, randArr, insertTime, eraseTime, findTime, iterationTime, summ);
	logInfoSkim<<"std::map insert ns = " << insertTime * 1e9;
	logInfoSkim<<"std::map erase ns = " << eraseTime * 1e9;
	logInfoSkim<<"std::map find ns = " << findTime * 1e9;
	logInfoSkim<<"std::map iteration ns = " << iterationTime * 1e9;

#ifdef _MSC_VER
	testStdContainer(stdhashmap, cyclesCount, megaCyclesCount, randArr, randArr, insertTime, eraseTime, findTime, iterationTime, summ);
	logInfoSkim<<"std::hash_map insert ns = " << insertTime * 1e9;
	logInfoSkim<<"std::hash_map erase ns = " << eraseTime * 1e9;
	logInfoSkim<<"std::hash_map find ns = " << findTime * 1e9;
	logInfoSkim<<"std::hash_map iteration ns = " << iterationTime * 1e9;
#endif

	if(testContainer(rbtmap, cyclesCount, megaCyclesCount, randArr, randArr, stdmap, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"RedBlackTreeMap insert ns = " << insertTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap find ns = " << findTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! RedBlackTreeMap FAIL";

	if(testContainer(hashTable, cyclesCount, megaCyclesCount, randArr, randArr, stdmap, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"HashTable insert ns = " << insertTime * 1e9;
		logInfoSkim<<"HashTable erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"HashTable find ns = " << findTime * 1e9;
		logInfoSkim<<"HashTable iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! HashTable FAIL";

	if(testContainer(hashMap, cyclesCount, megaCyclesCount, randArr, randArr, stdmap, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"HashMap insert ns = " << insertTime * 1e9;
		logInfoSkim<<"HashMap erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"HashMap find ns = " << findTime * 1e9;
		logInfoSkim<<"HashMap iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! HashMap FAIL";
	
	if(testContainer(hashArray, cyclesCount, megaCyclesCount, randArr, randArr, stdmap, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"HashArray insert ns = " << insertTime * 1e9;
		logInfoSkim<<"HashArray erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"HashArray find ns = " << findTime * 1e9;
		logInfoSkim<<"HashArray iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! HashArray FAIL";

	if(testContainer(sortedArray, cyclesCount, megaCyclesCount, randArr, randArr, stdmap, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"SortedArray insert ns = " << insertTime * 1e9;
		logInfoSkim<<"SortedArray erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"SortedArray find ns = " << findTime * 1e9;
		logInfoSkim<<"SortedArray iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! SortedArray FAIL";

	if(testContainer(rbtmapCellAlloc, cyclesCount, megaCyclesCount, randArr, randArr, stdmap, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"RedBlackTreeMap<uint, CellAllocator> time ns = " << insertTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap<uint, CellAllocator> erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap<uint, CellAllocator> find ns = " << findTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap<uint, CellAllocator> iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! RedBlackTreeMap<uint, CellAllocator> FAIL";

	rbtmapCellAlloc.allocator().defragment();
	if(testContainerVecrify(rbtmapCellAlloc, stdmap))
		logInfoSkim<<"RedBlackTreeMap<uint, CellAllocator>::defragemnt OK ";
	else
		logInfoSkim<<"! RedBlackTreeMap<uint, CellAllocator>::defragemnt FAIL";
	//rbtmapCellAlloc.clear();

	

	std::map<Base::String, Base::uint> stdmapS;
	Base::RedBlackTreeMap< Base::Pair<Base::String, Base::uint> > rbtmapS;
	Base::HashTable< Base::Pair<Base::String, Base::uint> > hashTableS;
	Base::HashMap< Base::Pair<Base::String, Base::uint> > hashMapS;
	Base::HashArray< Base::Pair<Base::String, Base::uint> > hashArrayS;
	Base::RedBlackTreeMap< Base::Pair<Base::String, Base::uint>, AllocatorWrapper<TCellDefragmentAllocator< Base::RedBlackTreeMapNodeT<Pair<Base::String, Base::uint>>::Type > > > rbtmapCellAllocS;

	Base::String* randStrArr = new Base::String[cyclesCount];
	for(Base::uint i=0; i < cyclesCount; i++)
		randStrArr[i] << Base::rand(0,100000000);

	testStdContainer(stdmapS, cyclesCount, megaCyclesCount, randStrArr, randArr, insertTime, eraseTime, findTime, iterationTime, summ);
	logInfoSkim<<"std::map<String> time ns = " << insertTime * 1e9;
	logInfoSkim<<"std::map<String> erase ns = " << eraseTime * 1e9;
	logInfoSkim<<"std::map<String> find ns = " << findTime * 1e9;
	logInfoSkim<<"std::map<String> iteration ns = " << iterationTime * 1e9;

	if(testContainer(rbtmapS, cyclesCount, megaCyclesCount, randStrArr, randArr, stdmapS, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"RedBlackTreeMap<String> time ns = " << insertTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap<String> erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap<String> find ns = " << findTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap<String> iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! RedBlackTreeMap<String> FAIL";

	if(testContainer(rbtmapCellAllocS, cyclesCount, megaCyclesCount, randStrArr, randArr, stdmapS, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"RedBlackTreeMap<String, CellAllocator> time ns = " << insertTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap<String, CellAllocator> erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap<String, CellAllocator> find ns = " << findTime * 1e9;
		logInfoSkim<<"RedBlackTreeMap<String, CellAllocator> iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! RedBlackTreeMap<String, CellAllocator> FAIL";

	rbtmapCellAllocS.allocator().defragment();
	if(testContainerVecrify(rbtmapCellAllocS, stdmapS))
		logInfoSkim<<"RedBlackTreeMap<String, CellAllocator>::defragemnt OK ";
	else
		logInfoSkim<<"! RedBlackTreeMap<String, CellAllocator>::defragemnt FAIL";
	//rbtmapCellAllocS.clear();

	if(testContainer(hashMapS, cyclesCount, megaCyclesCount, randStrArr, randArr, stdmapS, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"HashMap<String> time ns = " << insertTime * 1e9;
		logInfoSkim<<"HashMap<String> erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"HashMap<String> find ns = " << findTime * 1e9;
		logInfoSkim<<"HashMap<String> iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! HashMap<String> FAIL";
	
	
	if(testContainer(hashArrayS, cyclesCount, megaCyclesCount, randStrArr, randArr, stdmapS, insertTime, eraseTime, findTime, iterationTime, summ))
	{
		logInfoSkim<<"HashArray<String> time ns = " << insertTime * 1e9;
		logInfoSkim<<"HashArray<String> erase ns = " << eraseTime * 1e9;
		logInfoSkim<<"HashArray<String> find ns = " << findTime * 1e9;
		logInfoSkim<<"HashArray<String> iteration ns = " << iterationTime * 1e9;
	}
	else
		logInfoSkim<<"! HashArray<String> FAIL";

	

	delete[] randArr;

	/*
	timer.dt();
	Base::BiMap<float, float> crsp;
	for(Base::uint i=1; i < Count; i++){
		float f = float(rang[i]);
		crsp.insert(isInserted, f, f);
	}
	logInfoSkim<<"BiMap insert time ns = %lf", timer.dt() * 1e9 / (Count-1));

	timer.dt();
	for(Base::uint i=1; i < Count; i+=2)
		crsp.erase1((float)rang[i]);
	logInfoSkim<<"BiMap erase time ns = %lf", timer.dt() * 1e9 / (Count/2));

	timer.dt();
	for(Base::uint i=1; i < Count; i++){
		Base::BiMap<float, float>::Iterator n = crsp.find0(rang[i]);
		if(n != crsp.end())
			Assert(n.key0() == n.key1());
	}
	logInfoSkim<<"BiMap find time ns = %lf", timer.dt() * 1e9 / (Count-1));
	logInfoSkim<<"for all summ %d" << " " << summ;

	*/
	logInfoSkim<<"summ " << summ;
	logInfoSkim<<".";
}