Hi Guys,
Please help me to build Lambda expression for below C# for loop , Because the below for loop getting high CPU..
for (int i = 1; i <= dQuantity; )
{
double dlRnd = rnFirst.NextDouble();//with seed
if (dlRnd < 0.0001)
dlRnd += 0.012;
//string strRndFirstDgt = dlRnd.ToString().Substring(2, iFirstPinLng);
long strRndFirstDgt = ExtractDigits(dlRnd, 2, iFirstPinLng);
//----Second Rnd ------ 0.6 91979 52919 26617
double dlSecondRnd = rnSecond.NextDouble(); //Without Seed. 58535 03461 123
if (dlSecondRnd < 0.0001)
dlSecondRnd += 0.012;
long strRndSecondLastsixDgt = ExtractDigits(dlSecondRnd, dlSecondRnd.ToString().Length - iSecondPinLng, iSecondPinLng);
//string strRndSecondLastsixDgt1 = dlSecondRnd.ToString().Substring(dlSecondRnd.ToString().Length - iSecondPinLng, iSecondPinLng);
long conCan = Convert.ToInt64(strRndFirstDgt.ToString() + Convert.ToString(strRndSecondLastsixDgt));
long temp;
temp = Convert.ToInt64(conCan) + DateTime.Now.Ticks; //addition to pin+ datetime Ticks
int intRndThird = rnThird.Next(1, 10);//To avoid the prefix value 0's;
// string conCanRnd = intRndThird.ToString() + Convert.ToString(ExtractDigits(temp,temp.ToString().Length - pinLength, pinLength - 1));
long conCanRnd = Convert.ToInt64(stInt.ToString() + intRndThird.ToString() + (temp.ToString().Substring(temp.ToString().Length - pinLength, pinLength - 1)));
// long sessionconcatpins = Convert.ToInt64(stInt.ToString() + conCanRnd); // Append Concurent User Hit Count in to PINS
if (lstpins.Add(conCanRnd))
i++;
if (i % 100 == 0)
{
lngDateTicker = DateTime.Now.Ticks;
strSeedLastNineDgt = lngDateTicker.ToString().Substring(7, 9);
rnFirst = new Random(Convert.ToInt32(strSeedLastNineDgt));
}
}
VulpesPosted Mar 3, 2015, 5:27 AM
LINQ may make certain types of programming easier but it doesn't improve performance.
It might even make performance worse because it can introduce inefficiencies (such as unnecessary loop iterations) which would be eliminated in 'hand written' code.
Sivasankaran GurusamyPosted Mar 3, 2015, 12:30 AM
The purpose of this is to generate Random numbers with max 1 lakhs quantity.
Jignesh TrivediPosted Mar 2, 2015, 11:50 PM
Hi,
You want to replace above FOR with LINQ right?
As per my knowledge, In this case LINQ is also use for loop / while loop internally to perform the operation.
so there are no performance improve when you use LINQ...
hope this will help you.
Vithal WadjePosted Mar 2, 2015, 9:46 AM