다음 두 프로그램 간의 성능 차이를 확인하려고 시도 중입니다. 그러나 나는 아무런 차이점도 발견하지 못했다. 이게 정상인가? 윈도우 코어 2 듀오 M/C 비주얼 스튜디오에서 실행 임 2010 Express Edition을계산 집약적 인 C# 프로그램의 이점이 있습니까?
프로그램 1 (100 개 실행에 대해 평균 : 824.11 밀리 초) :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace MultiThreading
{
class Program
{
public static Stopwatch stopwatch;
static void Main(string[] args)
{
stopwatch = new Stopwatch();
stopwatch.Start();
//Thread t = new Thread(WriteY);
//t.Start();
for (int i = 0; i < 10000; i++)
{
Console.Write("x{0} ", i);
}
WriteY();
Console.WriteLine("Time taken in milliseconds: {0}", stopwatch.ElapsedMilliseconds);
Console.ReadLine();
}
static void WriteY()
{
for (int i = 0; i < 10000; i++)
{
Console.Write("y{0} ", i);
}
//Console.WriteLine("Time taken in milliseconds: {0}", stopwatch.ElapsedMilliseconds);
//Console.ReadLine();
}
프로그램 2 (평균 100 실행 : 828.11 MS) :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Threading;
namespace MultiThreading
{
class Program
{
public static Stopwatch stopwatch;
static void Main(string[] args)
{
stopwatch = new Stopwatch();
stopwatch.Start();
Thread t = new Thread(WriteY);
t.Start();
for (int i = 0; i < 10000; i++)
{
Console.Write("x{0} ", i);
}
//WriteY();
Console.WriteLine("Time taken in milliseconds: {0}", stopwatch.ElapsedMilliseconds);
Console.ReadLine();
}
static void WriteY()
{
for (int i = 0; i < 10000; i++)
{
Console.Write("y{0} ", i);
}
//Console.WriteLine("Time taken in milliseconds: {0}", stopwatch.ElapsedMilliseconds);
//Console.ReadLine();
}
}
}
-1. 그대는 어떤 계산도하지 않으므로 "계산 집약적 인"것은 이것이 의미하는 기본적인 오해입니다. Isntead 당신이 할 일은 콘솔 출력 메커니즘에 의해 직렬화되는 Console.WriteLine IO입니다. – TomTom