오브젝트 콜렉션에 Plinq (병렬 linq)를 사용해 보았을 때 기본적인 질문이 생겼다. Plinq Vs 정상 작동에는 실행 시간면에서 많은 차이가 없다는 것이 관찰되었다. 아무도 내 코드를 확인하고 왜 그런 일이 일어나는지 조언 해 줄 수 있습니까? i7 프로세서에서이 코드를 실행했습니다. 6 : 411 초 : MilliSeconds 서병렬 Linq가 객체 콜렉션
경과 시간, 병렬 모드 : 6:68 초 : 밀리 초 상기 코드
class Program
{
static void Main(string[] args)
{
new Program().Plinq();
new Program().linq();
Console.ReadLine();
}
void Plinq()
{
DateTime startTime = DateTime.Now;
var query1 = (from port in new XpressEntities().Portfolios.Take(1000000)
select new port { PortId = port.PORT_ID, CFAC = port.CFAC }).ToList<port>();
query1.AsParallel().Where(e => e.PortId == 0);
TimeSpan ts = DateTime.Now.Subtract(startTime);
Console.WriteLine("Time Elapsed: {0} Seconds:MilliSeconds in Paralel mode", ts.Seconds + ":" + ts.Milliseconds);
}
void linq()
{
DateTime startTime = DateTime.Now;
var query1 = (from port in new XpressEntities().Portfolios.Take(1000000)
select new port { PortId = port.PORT_ID, CFAC = port.CFAC }).ToList<port>();
query1.Where(e => e.PortId == 0);
TimeSpan ts = DateTime.Now.Subtract(startTime);
Console.WriteLine("Time Elapsed: {0} Seconds:MilliSeconds in Normal mode", ts.Seconds + ":" + ts.Milliseconds);
}
}
class port
{
public int PortId { get; set; }
public string CFAC { get; set; }
}
결과
시간 경과 표준 모드
대부분의 시간은 'var query1'을 할당하는 것으로 예상됩니다. –
맞습니다. 'Where' 만 측정해야합니다 (Stopwatch 클래스 사용) –