Created
September 12, 2014 13:41
-
-
Save odedw/d6a3f493c01de4f10264 to your computer and use it in GitHub Desktop.
Parallel Map Generation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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