Skip to content

Instantly share code, notes, and snippets.

@odedw
Created September 12, 2014 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odedw/d6a3f493c01de4f10264 to your computer and use it in GitHub Desktop.
Save odedw/d6a3f493c01de4f10264 to your computer and use it in GitHub Desktop.
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