Archived

This topic is now archived and is closed to further replies.

ZachO

VB/C++ test

Recommended Posts

I don't want to start a huge fight over which language is better, etc. I was just wodnerting, if anyone cna critique my code. I wanted to test which language can add 0 to 9999999 the fastest. Using my code, VB did it in 422ms, and c++ did it in 78ms. I ran the test 10 times each. Note: I couldn't find which header file gettickcount was in, so i just used ddraw.h. VB Code: Private Declare Function GetTickCount Lib "kernel32" () As Long Private Sub Form_Load() Dim I As Long, Sum As Double Dim StartT As Long, EndT As Long StartT = GetTickCount() For I = 0 To 9999999 Sum = Sum + I Next I EndT = GetTickCount() MsgBox (EndT - StartT) End Sub C++ code: #include <iostream.h> #include <ddraw.h> void main() { long start = 0, end = 0, i = 0; double sum = 0; start = GetTickCount(); for(i = 0; i < 9999999; i++) sum = sum = i; end = GetTickCount(); cout << (end - start); } Thank you. [edited by - zacho on July 25, 2003 8:31:23 PM]

Share this post


Link to post
Share on other sites
to convert and optimize 80k face object from ASE to my format took 24 hours with vb (using collection for storage) ... It only took less then 10 seconds with C++


I wrote it in vb first to save time thinking I would save time ... go figure

Share this post


Link to post
Share on other sites
VB isn''t supposed to create fast programs - just to save you time while coding

two questions though - First, I''m assuming that this is a typo:
"sum = sum = i;"

Second, did you run the vb program in debug mode, or did you actually build an exe and then ran that?


Note, I''m not saying that you can''t make fairly fast programs in vb - but it is more easy to make them slow than in C++.

"I woke up sweating and clutching my pillow. Thankfully the powerful and reassuring visage of Optimus Prime staring back at me from my pillow case served to ease my frayed nerves. Like the giant robotic father I never had he always knows just what to say" - Gabe, Penny-Arcade

Alexandre Moura

Share this post


Link to post
Share on other sites
C++ wont run the .exe of the program, for some ungodly reason. I ran the .exe of the vb project and it went from 422 to 105, now beating c++.

And no, that was not a typo, nice catch! C++ went up to 125 with the fix, in the IDE though. Cant test the .exe.

Share this post


Link to post
Share on other sites
Tecnically, when running a C++ program in the IDE you are running the .Exe (are you building with the release version btw?) - I don''t know if running it in debug mode slows it down, but if you''re using the Ctrl+F5 (in VS .Net, don''t remeber the shortcut in vs6) then the ide is just building the exe and then launching it, performance should be equal to running the exe yourself.
In vb it''s a little more complex - when running in the ide, you are running the program in a virtual machine, which is pretty slow - when you build it to an exe, then you get a compiled program that shouldn''t be much slower than C++ for low level instructions (like adding numbers)

One last thing though - things on the order of 100ms could be easily influenced by the program loading, momentary disk accesses, etc - I would increase the number of sums at least tenfold to get a more averaged out value...

"I woke up sweating and clutching my pillow. Thankfully the powerful and reassuring visage of Optimus Prime staring back at me from my pillow case served to ease my frayed nerves. Like the giant robotic father I never had he always knows just what to say" - Gabe, Penny-Arcade

Alexandre Moura

Share this post


Link to post
Share on other sites
Tests like this are useless for determining which language is best. It depends on which one you''re more comfortable with, what exactly you''re developing, and how much time you have to get it done. You''re not going to write a Doom III clone in VB. That''s not the purpose of the language. Small to medium size games are quite possible in VB however now that it has access to DirectX. It''ll probably take you up to half as long to create something in VB than in C++, all things being equal. I''ve been using both for over 10 years. Any serious game development you''ll want to use C++. If you''re just looking to create small games, VB will do the job and you''ll probably get it done quicker.

Share this post


Link to post
Share on other sites