Monday 3 April 2017

c# - .Net Framework is much slower than .Net Core?

So i build this code in .Net Core and it works wonderfully good
But when i use this code in .NetFramework It's really slow and not picking up the pace



    static int wichOneIsBigger(Random rand, int number)
{
//65-90 (Upper) 97 122 (Lower)

Exception e = new Exception("Number must be 0 for lower case and 1 for upper case");
if (number != 0 && number != 1)
throw e;
else
if (number == 0)
return rand.Next(97, 122);
else
return rand.Next(65 - 90);
}
static void Main()

{
string txt = null;

Random rand = null;
int length = 0;
Console.WriteLine("Please type a number that is above 1: ");

txt = Console.ReadLine();
length = Convert.ToInt32(txt);


string[] words = new string[length];
for (int i = 0; i < length; i++)
{
rand = new Random();
int characters = rand.Next(4, 10);
int randCharacter = 0;
int wichOne = 0;
string word = "";
for (int num = 0; num < characters; num++)
{

wichOne = rand.Next(0, 1);
randCharacter = wichOneIsBigger(rand, wichOne);

word += Convert.ToChar(randCharacter);
}
words[i] = word;
}

foreach (string item in words)
Console.WriteLine(item);


GC.Collect();
Console.ReadKey();
}


when im using .Net Core it's giving me this result for example the length is 5:



gaerantd
dxunjxtw

gevnyiqb
xhpsvfqu
gnnkaulxg


But when im using .Net Framework it giving me this



aist
aist
aist

aist
aist


Why in the .Net Framework it wont picking up the pace?
I didnt programmed for 2.5 years and i dont remmember .Net Framework being this slow



By the way do you guys have any suggestion of my code?
Can i write it better and etc?




Thanks for the help :)

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...