Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parallel Map Generation
[Test]
public void ParallelMapGenerationTest()
{
const int SIZE = 1000;
const int NUMBER_OF_ROOMS = 320;
const int NUMBER_OF_PARALLEL_CALLS = 16;
var generator = new DungeonGenerator<Cell>();
DateTime start = DateTime.Now;
//One big map
for (var i = 0; i < ITERATIONS; i++)
{
Console.Write(i + ",");
generator.GenerateA()
.DungeonOfSize(SIZE, SIZE)
.VeryRandom()
.SomewhatSparse()
.WithMediumChanceToRemoveDeadEnds()
.WithLargeSizeRooms()
.WithRoomCount(NUMBER_OF_ROOMS)
.Now();
}
Console.WriteLine("One Big map: Average of {0} seconds", DateTime.Now.Subtract(start).TotalSeconds / ITERATIONS);
var sizeOfSmallMap = (int)(SIZE / Math.Sqrt(NUMBER_OF_PARALLEL_CALLS));
var roomsPerMap = NUMBER_OF_ROOMS / NUMBER_OF_PARALLEL_CALLS;
start = DateTime.Now;
//Several small maps in parallel
for (var i = 0; i < ITERATIONS; i++)
{
Console.Write(i + ",");
Parallel.For(0, NUMBER_OF_PARALLEL_CALLS, (j) => generator.GenerateA()
.DungeonOfSize(sizeOfSmallMap, sizeOfSmallMap)
.VeryRandom()
.SomewhatSparse()
.WithMediumChanceToRemoveDeadEnds()
.WithLargeSizeRooms()
.WithRoomCount(roomsPerMap)
.Now());
}
Console.WriteLine("Several small maps in parallel: Average of {0} seconds", DateTime.Now.Subtract(start).TotalSeconds / ITERATIONS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment