feat: improved simulation benchmarking
This commit is contained in:
		
							parent
							
								
									03da0b18e0
								
							
						
					
					
						commit
						e1bb3beeed
					
				| 
						 | 
					@ -131,15 +131,16 @@ static void FindBorn(size_t segment, size_t length) {
 | 
				
			||||||
	bornMutex.unlock();
 | 
						bornMutex.unlock();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MULTITHREADING 0
 | 
					#define MULTITHREADING 1
 | 
				
			||||||
static uint64_t generationTime{ 0 };
 | 
					static uint64_t generationStartTime{ 0 };
 | 
				
			||||||
static bool logGenerationTime{ false };
 | 
					static bool logGenerationTime{ false };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void PopulateChanges() {
 | 
					static void PopulateChanges() {
 | 
				
			||||||
	generationTime = SDL_GetTicksNS();
 | 
					 | 
				
			||||||
	logGenerationTime = true;
 | 
					 | 
				
			||||||
#if MULTITHREADING
 | 
					#if MULTITHREADING
 | 
				
			||||||
	constexpr size_t split{ 2 };
 | 
						constexpr size_t split{ 1 };
 | 
				
			||||||
 | 
						SDL_Log("Multithreading ON");
 | 
				
			||||||
 | 
						logGenerationTime = true;
 | 
				
			||||||
 | 
						generationStartTime = SDL_GetTicksNS();
 | 
				
			||||||
	size_t const seg_length{ living.size() / split };
 | 
						size_t const seg_length{ living.size() / split };
 | 
				
			||||||
	for (size_t i{ 0 }; i < split; ++i) {
 | 
						for (size_t i{ 0 }; i < split; ++i) {
 | 
				
			||||||
		threading::tasks.ScheduleTask(std::bind(FindOverpopulated, i, seg_length));
 | 
							threading::tasks.ScheduleTask(std::bind(FindOverpopulated, i, seg_length));
 | 
				
			||||||
| 
						 | 
					@ -147,6 +148,9 @@ static void PopulateChanges() {
 | 
				
			||||||
		threading::tasks.ScheduleTask(std::bind(FindBorn, i, seg_length));
 | 
							threading::tasks.ScheduleTask(std::bind(FindBorn, i, seg_length));
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
 | 
						SDL_Log("Multithreading OFF");
 | 
				
			||||||
 | 
						logGenerationTime = true;
 | 
				
			||||||
 | 
						generationStartTime = SDL_GetTicksNS();
 | 
				
			||||||
	FindOverpopulated(0, living.size());
 | 
						FindOverpopulated(0, living.size());
 | 
				
			||||||
	FindUnderpopulated(0, living.size());
 | 
						FindUnderpopulated(0, living.size());
 | 
				
			||||||
	FindBorn(0, living.size());
 | 
						FindBorn(0, living.size());
 | 
				
			||||||
| 
						 | 
					@ -258,7 +262,7 @@ void Draw(SDL_Renderer *renderer, double cellSizePercent) {
 | 
				
			||||||
	bornMutex.unlock();
 | 
						bornMutex.unlock();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (logGenerationTime) {
 | 
						if (logGenerationTime) {
 | 
				
			||||||
		SDL_Log("End Generation %lf", double(SDL_GetTicksNS() - generationTime) * 0.0000000001);
 | 
							SDL_Log("End Generation %lf", double(SDL_GetTicksNS() - generationStartTime) * 0.0000000001);
 | 
				
			||||||
		logGenerationTime = false;
 | 
							logGenerationTime = false;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue