Witam,
nie będę owijał w bawełnę, nie mam pojęcia jak zrobić instrumentację kodu. Mam za zadanie:
"Dana jest poniższa implementacja algorytmu badania czy zadana liczba jest pierwsza:
bool IsPrime(BigInteger Num)
{
if (Num < 2) return false;
else if (Num < 4) return true;
else if (Num % 2 == 0) return false;
else for (BigInteger u = 3; u < Num / 2; u += 2)
if (Num % u == 0) return false;
return true;
}
zaproponuj bardziej efektywny algorytm przy zachowaniu niezmienionego interfejsu podprogramu. Przeprowadzić analizę za pomocą instrumentacji i pomiarów czasu. "
No i wydaje mi się że kod "przed instrumentacją" jest dobrze napisany, lecz samej takiej analizy nie potrafię wykonać. Myślę, że powinienem użyć system.diagnostics.
Moje wypociny:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System.Diagnostics;
namespace LiczbyPierwsze
{
class Program
{
static int a;
// static ulong DivsNum;
static bool AlgorytmPrzykładowy(BigInteger Num)
{
if (Num < 2) return false;
else if (Num < 4) return true;
else if (Num % 2 == 0) return false;
else for (BigInteger u = 3; u < Num / 2; u += 2)
if (Num % u == 0) return false;
return true;
}
//--------------------------
static bool AlgorytmPrzykładowyInstrumentacja(BigInteger Num)
{
}
//--------------------------
static bool AlgorytmLepszy(BigInteger Num)
{
for (int i = 2; i < a; i++)
{
if (a % i == 0)
{
return false;
}
}
return true;
}
//---------------------------
static bool AlgorytmLepszyInstrumentacja(BigInteger Num)
{
//
}
//---------------------------
static bool AlgorytmJeszczeLepszy(BigInteger Num)
{
if (Num < 2) return false;
else for (BigInteger u = 2; u * u <= Num; u++)
return false;
return true;
//
}
//----------------------
static bool AlgorytmJeszczeLepszyInstrumentacja(BigInteger Num)
{
//
}
//----------------------
static void Main(string[] args)
{
BigInteger[] PrimeNums = new BigInteger[] { 101, 1009, 10091, 100913, 1009139, 10091401, 100914061, 1009140611, 10091406133, 100914061337, 1009140613399 };
// testy
Console.ReadKey();
}
}
}
Proszę o pomoc.