Sunday, July 3, 2011

Genetic Algorithm – Part 7 - Compare SQL and C# code

Now it is time to compare SQL and C# implementation. Below are the comparisons for 1000 generations.


The results are staggering the C# code is working way faster. There is couple of reason for that. First one uses of all processor cores. Picture below is for C# code, use can see all the processor cores being utilized properly.

(click on image to enlarge)


Below is the CPU utilisation for SQL code.






If you look at the CPU utilization in case C# all the cores are being used, while in case of SQL only one core is being used. If you look carefully in picture at the CPU usage percentage is 78.03 % for C#, while it is 8.77% for SQL.

Second reason is I have to represent DNA, board and other constructs as string in SQL and do manipulations, while I have data structure like arrays in C#, which has proved to be faster. Remember each code path runs one million times, so even slight benefit turns out to be significant gain in the end.

No comments:

Post a Comment