This is the original VB. NET version I wrote earlier:
Http://www.cnblogs.com/RChen/archive/2010/05/17/1737587.html
After being converted to the C # version, some refactoring is also performed. This includes modifying to a strong type and using Parallel. ForEach, but failed to receive the expected results. Performance improvement is relatively small.
After research, we found that the key to the problem is to pruning the possibility of traversal in some way, so as to reduce the number of traversal times and improve performance. Besides, because the results are implemented through yield return and IEnumerable, IList or Array is not implemented. therefore, it does not support Parallel split by index range in essence. the ForEach method is used, and the actual estimation is several inefficient chunk round-reading methods, so there is thread synchronization overhead between each chunk, as mentioned above. This performance optimization will have to be available for further research.
The following is the implementation code of the current situation:
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
System.Threading.Tasks;
using
System.Collections;
namespace
NonDeterministicEngineCS
{
class
Program
{
static
void
Main(
string
[] args)
{
Benchmarking(
new
Action(Test1),
"Test1 () execution is completed, which takes {0} milliseconds. "
);
Console.WriteLine(
"===================================================="
);
Benchmarking(
new
Action(Test2),
"Test2 () execution is completed, which takes {0} milliseconds. "
);
Console.WriteLine(
"===================================================="
);
Benchmarking(
new
Action(Test3),
"Test3 () execution is completed, which takes {0} milliseconds. "
);
Console.ReadLine();
}
// A simple test example
public
static
void
Test1()
{
NonDeterministicEngine engine =
new
NonD