浏览代码

Some additional mem usage benches in sparse array

Panagiotis Christopoulos Charitos 8 年之前
父节点
当前提交
7f7ea837fb
共有 1 个文件被更改,包括 20 次插入4 次删除
  1. 20 4
      tests/util/SparseArray.cpp

+ 20 - 4
tests/util/SparseArray.cpp

@@ -169,13 +169,25 @@ ANKI_TEST(Util, SparseArray)
 	}
 	}
 }
 }
 
 
+static PtrSize akAllocSize = 0;
 static ANKI_DONT_INLINE void* allocAlignedAk(void* userData, void* ptr, PtrSize size, PtrSize alignment)
 static ANKI_DONT_INLINE void* allocAlignedAk(void* userData, void* ptr, PtrSize size, PtrSize alignment)
 {
 {
+	if(ptr == nullptr)
+	{
+		akAllocSize += size;
+	}
+
 	return allocAligned(userData, ptr, size, alignment);
 	return allocAligned(userData, ptr, size, alignment);
 }
 }
 
 
+static PtrSize stlAllocSize = 0;
 static ANKI_DONT_INLINE void* allocAlignedStl(void* userData, void* ptr, PtrSize size, PtrSize alignment)
 static ANKI_DONT_INLINE void* allocAlignedStl(void* userData, void* ptr, PtrSize size, PtrSize alignment)
 {
 {
+	if(ptr == nullptr)
+	{
+		stlAllocSize += size;
+	}
+
 	return allocAligned(userData, ptr, size, alignment);
 	return allocAligned(userData, ptr, size, alignment);
 }
 }
 
 
@@ -188,7 +200,7 @@ ANKI_TEST(Util, SparseArrayBench)
 	using StlMap = std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<int, int>>>;
 	using StlMap = std::unordered_map<int, int, std::hash<int>, std::equal_to<int>, HeapAllocator<std::pair<int, int>>>;
 	StlMap stdMap(10, std::hash<int>(), std::equal_to<int>(), allocStl);
 	StlMap stdMap(10, std::hash<int>(), std::equal_to<int>(), allocStl);
 
 
-	using AkMap = SparseArray<int, U32, 256, 16>;
+	using AkMap = SparseArray<int, U32, 1024, 16>;
 	AkMap akMap;
 	AkMap akMap;
 
 
 	HighRezTimer timer;
 	HighRezTimer timer;
@@ -239,8 +251,7 @@ ANKI_TEST(Util, SparseArrayBench)
 		ANKI_TEST_LOGI("Inserting bench: STL %f AnKi %f | %f%%", stlTime, akTime, stlTime / akTime * 100.0);
 		ANKI_TEST_LOGI("Inserting bench: STL %f AnKi %f | %f%%", stlTime, akTime, stlTime / akTime * 100.0);
 	}
 	}
 
 
-// Search
-#if 1
+	// Search
 	{
 	{
 		int count = 0;
 		int count = 0;
 
 
@@ -265,7 +276,12 @@ ANKI_TEST(Util, SparseArrayBench)
 
 
 		ANKI_TEST_LOGI("Find bench: STL %f AnKi %f | %f%%", stlTime, akTime, stlTime / akTime * 100.0);
 		ANKI_TEST_LOGI("Find bench: STL %f AnKi %f | %f%%", stlTime, akTime, stlTime / akTime * 100.0);
 	}
 	}
-#endif
+
+	// Mem usage
+	const PtrSize stlMemUsage = stlAllocSize + sizeof(stdMap);
+	const PtrSize akMemUsage = akAllocSize + sizeof(akMap);
+	ANKI_TEST_LOGI(
+		"Mem usage: STL %llu AnKi %llu | %f%%", stlMemUsage, akMemUsage, F64(stlMemUsage) / akMemUsage * 100.0);
 
 
 	// Deletes
 	// Deletes
 	{
 	{