vb.net2010 vc++2010 배열처리속도 의견을.......

ddulce의 이미지

vc++2010 express
vb.net2010 express

두개의 프로그램으로 같은 내용의 배열을 처리했을때 시간이 vb.net2010 이 두배이상 빠른데 원인이 어떤건가요?

vc++2010 express

#include "stdafx.h"
#include
#include
#include
#include
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
int* Array1 = new int[100000000];
time_t Start, End;
Start = clock();
for (int i = 0 ; i {
for (int j = 0 ; j {
Array1[j] = j;
}
End = clock();
cout }
getch();

return 0;
}

비주얼베이직////

vb.net2010 express

Public Class Form1

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim A_Test() As Integer = New Integer(100000000) {}
Dim nNow As Date = Now
If DataGridView1.Rows.Count > 0 Then DataGridView1.Rows.Clear()

For j As Integer = 0 To 9
For i As Integer = 0 To 100000000
A_Test(i) = i
Next
Dim nEnd As Date = Now
Dim Diw As TimeSpan = nEnd.Subtract(nNow)
DataGridView1.Rows.Add(Diw.ToString)
Application.DoEvents()
Next

End Sub
End Class

mirheekl의 이미지

직접 테스트해봤는데 양쪽이 거의 동일한 결과가 나왔습니다.

다만 조건을 똑같이 맞추기 위해서,
- 둘 다 콘솔프로그램으로 작성했습니다.
- 출력함수의 영향을 배제하기 위해 타이머값을 누적시키지 않고 턴마다 리셋했습니다.

VB.Net

	Sub Main()
		Dim A_Test() As Integer = New Integer(100000000) {}
		Dim swatch As Stopwatch = New Stopwatch()
 
		For j As Integer = 0 To 9
			swatch.Reset()
			swatch.Start()
			For i As Integer = 0 To 99999999
				A_Test(i) = i
			Next
			swatch.Stop()
			Console.WriteLine(swatch.Elapsed.ToString())
		Next
 
	End Sub

VC++ (Stopwatch 클래스는 https://code.google.com/p/cpp-stopwatch/ 여기서 가져왔습니다.)

 
int _tmain(int argc, _TCHAR* argv[])
{
	int* Array1 = new int[100000000];
 
	Stopwatch swatch;
	swatch.set_mode(REAL_TIME);
 
	for (int i = 0 ; i< 10; i++)
	{
		swatch.start(__FUNCTION__);
		for (int j = 0 ; j < 100000000; j ++)
		{
			Array1[j] = j;
		}
		swatch.stop(__FUNCTION__);
		cout << swatch.get_last_time(__FUNCTION__) << endl;
	}
 
	getch();
	return 0;
}

릴리즈 모드 결과:

VB.Net   
00:00:00.1853516
00:00:00.1056807
00:00:00.1067857
00:00:00.1041866
00:00:00.1064804
00:00:00.1045881
00:00:00.1072518
00:00:00.1060532
00:00:00.1054853
00:00:00.1041395
 
VC++
0.147008
0.100006
0.0940056
0.0920053
0.0950053
0.0950055
0.0950053
0.0930054
0.0930054
0.0940053

여러 번 해도 거의 비슷한 결과가 나옵니다. (VC++쪽이 아주 약간 빠르지만, 시간 측정 함수 자체의 정확도 등을 고려하지 않고 있음에 주의) 특성상 그럴수밖에 없기도 하고요.

따라서 글쓴 분이 하신 테스트에서, 릴리즈 모드에서도 VB.Net이 더 빠르게 나왔다면 아마 시간을 계산하고 화면에 출력하는 쪽의 퍼포먼스의 차이가 아닐까 생각합니다. 배열 처리 속도 차이가 아니고요.

--

ddulce의 이미지

초보자의 의견에 답해주신 님께 먼저 감사를 드립니다.
로또의 프로그램을 짜던중에 C++와 차이가 어떤가 하고 초보수준의 테스트를 했습니다.
특성상 반복(8백만개*6수)이 많은 관계로 반복을 위주로 테스트를 해보게 되었습니다.

다시한번 주신 프로그램으로 테스트를 해볼까 합니다.
늘 건강하시길 바랍니다.