Tuesday, July 21, 2009

Comparison of Average Execution Time : VB vs V++

time it takes for c++ to count to 1000000000: 8.125 seconds
time it takes for VB to count to 1000000000 : 19.203 seconds

VB Code:
  1. Option Explicit
  2. Private Declare Function GetTickCount Lib "kernel32" () As Long
  3. Dim firstnumber As Double
  4. Dim secondnumber As Double
  5. Dim thirdnumber As Double
  6. Private Sub Form_Load()
  7. secondnumber = 0
  8. firstnumber = GetTickCount()
  9. While secondnumber <= 1000000000#
  10. secondnumber = secondnumber + 1
  11. Wend
  12. thirdnumber = GetTickCount()
  13. MsgBox "time taken to count to 1000000000: " & thirdnumber - firstnumber
  14. End Sub


C++ Code:
#include "stdafx.h"
#include "iostream.h"
#include "windows.h"


// how long does it take the computer to increment a var 100000 times?
void main()
{
double firstnumber;
double secondnumber=0;
double thirdnumber;

firstnumber = GetTickCount();

while (secondnumber <= 1000000000)
{
secondnumber++;
}
thirdnumber = GetTickCount();
cout << "time taken: " << thirdnumber - firstnumber;
}

No comments: