protected override void ItemAction(int j) { if (Magma.IsPrime(j)) { _c++; } }
protected override void ItemAction(int item) { if (Magma.IsPrime(item)) { _primes.Add(item); } }
protected override void OnTorture() { while (!_abortSignal.IsCancellationRequested) { var count = 0; var part = Partitioner.Create(array); var syncRoot = new object(); void TestIfPrime(int j) { if (Magma.IsPrime(j)) { lock (syncRoot) count++; } } try { Parallel.ForEach(part, new ParallelOptions { MaxDegreeOfParallelism = Environment.ProcessorCount, CancellationToken = _abortSignal.Token }, TestIfPrime); } catch { } } }
protected override void ItemAction(int item) { if (Magma.IsPrime(item)) { lock (_syncLock) _c++; } }
protected override void Benchmark(int[] array, Stopwatch t, ref int count) { t.Start(); foreach (var j in array) { if (Magma.IsPrime(j)) { count++; } } t.Stop(); }
public override void Run(int[] array) { var c = 0; foreach (var j in array) { if (Magma.IsPrime(j)) { c++; } } Count = c; }
protected override void Benchmark(int[] array, Stopwatch t, ref int count) { t.Start(); count = array.Select(p => Magma.IsPrime(p)).Count(p => p); t.Stop(); }