Page 1 of 2 12 LastLast
Results 1 to 40 of 48

Thread: C++ VS Visual Basic?

  1. #1

    Thread Starter
    Lively Member outcast24817's Avatar
    Join Date
    Nov 2004
    Location
    USA
    Posts
    122

    Question C++ VS Visual Basic?

    I have heard pretty much everyone who knows about programming say that c++ is better than VB, from what i can see, vb does the same stuff C++ does, but with more readability, also, c++ doesnt seem to have any easy way to create buttons and professional looking user interfaces the way VB does. Is there any great speed difference between the two? and what are some other pros/cons of each?
    **not completely learned**
    Complete control of the registry ~

  2. #2
    Hyperactive Member boku's Avatar
    Join Date
    Dec 2004
    Posts
    386

    Re: C++ VS Visual Basic?

    If I remember correctly once read a review on both of them with a comparisson by a microsoft employee. Overall he did say Visual Basic was better as it has a lot more functions along with the easability.
    -BoKu-

  3. #3
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: C++ VS Visual Basic?

    Take a look at this one...
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  4. #4
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: C++ VS Visual Basic?

    If you need to know about the speed... well, I just did these partly to prove VB can be fast:

    http://www.vbforums.com/showthread.php?t=344694

    Those do pure maths a whole lot. As overall, VB is more developer friendly, while C or C++ gives you more control easily. In the other hand, you need to do much more when you have more control, so developing a program with VB is much faster than it is with C. While when the program gets big, in C it is handled better: I often hear people saying it is easy to control a big project in C, while it becomes a nightmare with VB. In the other hand, that is the point of VB: to do fast and to do small or middle sized programs.

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    I started out as a C/C++ programmer, well that's not the whole truth since I as many others first came in contact with computers learning the BASIC language. I was about 10-11 years old back in the late '70s and wrote cool programs like:
    Code:
    10 PRINT "Hello ";
    20 GOTO 10
    I later learned Pascal and then C and C++. But as a professional programmer I got my first job as a C++ programmer, the year was 1987 and I had just turned 19 (hmmm... I'm giving away my age here, one of those well preserved secrets). Anyhow, Windows where nowhere in sight yet so I wrote custom applications for DOS. When VB was first introduced in the early '90s I jumped on it faster then Pamela Anderson jumped Tommy Lee. But opposed to them my relationship with VB has been a long lucky one.

    But of course I've had to listen to my fellow programmers who called it a "toy language". Well, in the beginning it pretty much was. But we've all heard "real" programmers say things like that forever. "You can't do this in VB", "VB is an interpreted language, you can't even make real binaries with it", "How silly it is that you need all those run-time files"... and so on forever and ever... The guys that complained the most was those that jumped on the Java train very early... and of course Java isn't interpretated or needs a huge run-time does it? (I have nothing against Java, I use it often). Also other fellow C++ programmers wrote Windows application using MFC which of course also requires huge run-times.

    So much of their ados just didn't cut it. We have bin able to compile our VB programs to pure native code, creating the same kind of binaries as VC++ does, since version 5.

    I admit that when it comes to speed, you can write C++ programs that runs much faster then a VB program. But in many cases that just doesn't matter. For a regular desktop application, like a word processor, speed is not the main concern since your program will have more then enough time to process any input made by the user (what kind of computer runs slower then even the fastest of typewriters can type?). Today many applications use the Net, in which case the speed issue is in the network connections and server response times rather then in the execution of code.

    Let's compare another speed issue: The speed of development, to get what the customer wants delivered on time (nobody is going to pay you for two month extra work just so they will earn a few milliseconds in execution time). Well VB will be the winner here. There aren't many C++ RAD (rapid application development) tools but some do exist, like Borland C++ builder that comes with a Form package much like VB.

    So which is better the apple or the pear? Well, it first come down to taste but mainly what it comes down to is the usage. What will it be used for? I still does development in C++ when I need to. But that is actually not very often.

  6. #6
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: C++ VS Visual Basic?

    I totaly agree with Joacim Andersson...

    In VB takes one quarter of the time it takes in C++ to make an application. I made an application in VB at work (for work),(the system that we use now) that is quite big ~35000 lines (server + client), (and by the way Merri, I can manage it with no problem). I made it in my free time at work between the things I was supposed to do, and it took me about a 6 months to do (I still do maintenace for it). If I were to do the same thing in C++, I am SURE I would be still working on it right now (it's been a year and 3 months since I started it).

    I still use C++, but mostly when I need speed in VB...

    The same way I used to use ASM in C++, now I use C++ for VB. I usually make a DLL (Or ActiveX DLL) in C++ for the things I need to do really fast, like sound processing or bitmap compression/filters, stuff that requires lot's of loops,[edit]also multithreading[/edit], etc., and use VB as the interface.

    [edit]
    Actually, this is a thread with a good example of when I use C++ in VB:
    VB - Tone Recognition
    In the first post, it is VB only, and second post I made a DLL in C++ to speed up the processing (making it real-time)...
    Last edited by CVMichael; Jun 16th, 2005 at 10:45 PM.

  7. #7
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Re: C++ VS Visual Basic?

    Put it this way. The speed of execution difference between VB and C++ is enormous. C++ leaves VB in the dust. A simple mathematical loop will execute in a fraction of the time that it does in VB. To put it simply, advanced programing can only be done in C++. Something as simple as keyboard hooks cannot be done in VB, leaving you to make a DLL in C++ to accomplish the task. But don't get me wrong, getting a form to pop up in C++ is a rediculous task nontheless. If you're doing it from scratch, making a window appear in C++ will take you 15 minutes to program properly. You'll never have to deal with that in VB. Adding a form using code in VB is one line :P.
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  8. #8
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    Quote Originally Posted by VIP3R
    To put it simply, advanced programing can only be done in C++. Something as simple as keyboard hooks cannot be done in VB
    What do you consider to be advanced programming? I have no problem calling SetWindowsHookEx with WH_KEYBOARD_LL from VB to create a low level keyboard hook, or are you still using VB4?

  9. #9

    Thread Starter
    Lively Member outcast24817's Avatar
    Join Date
    Nov 2004
    Location
    USA
    Posts
    122

    Re: C++ VS Visual Basic?

    well, i wrote two programs, with vb 6 and c++ (microsoft visual studio 6)

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

    kinda dissapointing.. but oh well.
    here is the code, i tried to get everything exactly the same:

    VB
    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.  
    7. Private Sub Form_Load()
    8. secondnumber = 0
    9. firstnumber = GetTickCount()
    10.  
    11. While secondnumber <= 1000000000#
    12. secondnumber = secondnumber + 1
    13. Wend
    14. thirdnumber = GetTickCount()
    15. MsgBox "time taken to count to 1000000000: " & thirdnumber - firstnumber
    16.  
    17. 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;
    }
    this was using my xp home anthlon 2800 (2. GHZ)(they cheated me of 800 Mhz! i am going to have to overclock) with 512 megs ram (though that doesnt really matter)

    here are the exe's:
    http://www.geocities.com/outcast20087923/prog.zip
    they will be uploaded in a moment

    so i take it that if i made a video game in VB, it would run like, 19 / 8 = 2.5 times faster using directx?
    Last edited by outcast24817; Jun 17th, 2005 at 12:28 AM.
    **not completely learned**
    Complete control of the registry ~

  10. #10

    Thread Starter
    Lively Member outcast24817's Avatar
    Join Date
    Nov 2004
    Location
    USA
    Posts
    122

    Re: C++ VS Visual Basic?

    ok, they are uploaded now.
    (you have to run the C++ prog from the command prompt or batch file)

    what i found disgusting was that i got an error for not capitalizing "GetTickCount" when making the C++ version of the program. I looked around and i couldnt find any option to turn case sensitivity off, (or make it like VB where it corrects all instances for you) does anyone know how to fiddle with this feature?
    **not completely learned**
    Complete control of the registry ~

  11. #11
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: C++ VS Visual Basic?

    Did you turn all advanced optimizations on? Also, place the code behind a command button and not Form_Load.

  12. #12
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,123

    Re: C++ VS Visual Basic?

    While secondnumber <= 1000000000#, what is that sharp sign doing there?
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  13. #13
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    Well, if you in your game just going to count up to a billion it would be faster to write it in C++ . To make a little bit more fair comparison you should however remove the floating point error check in VB, since C++ doesn't have one.

  14. #14
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: C++ VS Visual Basic?

    Oh yes, you should also check VB doesn't need to do useless automatical data type conversion. It might do it now. I'd use Long datatype (was it, uh... Word or Integer in C?)


    As you can see, to do fast code with VB6, you need experience and knowledge on how to do it... you can't just do it and claim "it is so slow!"

  15. #15

    Thread Starter
    Lively Member outcast24817's Avatar
    Join Date
    Nov 2004
    Location
    USA
    Posts
    122

    Re: C++ VS Visual Basic?

    Joacim Andersson: i didnt get any errors when i compiled them
    dee-u: i dunno, it put the symbol there after i typed the number, i tried deleting it several times
    Merri: i dont see where the advanced optimizations are
    **not completely learned**
    Complete control of the registry ~

  16. #16
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: C++ VS Visual Basic?

    File > Make Project > Options > Compile > Advanced optimizations


    Also, you didn't get any errors because it doesn't go over... nothing causes an error. VB checks for it automatically, unless you turn it off in advanced optimizations.

  17. #17
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    Quote Originally Posted by outcast24817
    Joacim Andersson: i didnt get any errors when i compiled them
    I didn't say that you had an error I just said that you should remove the error check. VB has built in overflow checks so you can't assign a number higher then allowed to a variable. C++ doesn't have this which could cause unexpected results. Having the check makes the code safer but slower. You can remove these error checks before you compile the program. Also a console based application will always run faster then a Windows based app. You should to be fare make the C++ app into a Win32 windowed app before you compare them.

  18. #18

    Thread Starter
    Lively Member outcast24817's Avatar
    Join Date
    Nov 2004
    Location
    USA
    Posts
    122

    Re: C++ VS Visual Basic?

    actually, its called long in both C++ and VB, i think word is an old term for it

    Type Size Values
    unsigned short int 2 bytes 0 to 65,535
    short int 2 bytes -32,768 to 32,767
    unsigned long int 4 bytes 0 to 4,294,967,295
    long int 4 bytes -2,147,483,648 to 2,147,483,647
    int (16 bit) 2 bytes -32,768 to 32,767
    int (32 bit) 4 bytes -2,147,483,648 to 2,147,483,647
    unsigned int (16 bit) 2 bytes 0 to 65,535
    unsigned int (32 bit) 2 bytes 0 to 4,294,967,295
    char 1 byte 256 character values
    float 4 bytes 1.2e-38 to 3.4e38
    double 8 bytes 2.2e-308 to 1.8e308
    yes i could have used shorter vars. but i wanted to make this take a measurable amount of time, i figured 'why not?'
    **not completely learned**
    Complete control of the registry ~

  19. #19
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: C++ VS Visual Basic?

    The sharp simbol means that the number is a double, VB puts that automatically when the number is very large and WITHOUT decimal places (so you don't confuze it with long)
    Attached Images Attached Images  

  20. #20

    Thread Starter
    Lively Member outcast24817's Avatar
    Join Date
    Nov 2004
    Location
    USA
    Posts
    122

    Re: C++ VS Visual Basic?

    Joacim Andersson: ok, will do, but how exactly would i make it into a win32 project?
    Last edited by outcast24817; Jun 17th, 2005 at 12:47 AM.
    **not completely learned**
    Complete control of the registry ~

  21. #21
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    However, even when you turn optimization on you can always create faster applications using C++, nobody has claimed differently. It's just that there are very few real world applications where these differences actually make any difference.

  22. #22
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,802

    Re: C++ VS Visual Basic?

    Quote Originally Posted by outcast24817
    actually, its called long in both C++ and VB, i think word is an old term for it
    Actually, "word" is the NEW term for it...

  23. #23
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    The C++ standard doesn't set the boundaries for an int or a long. An int is at least 16-bit in size. Word is not a new term, a word is a 16bit integer. A double word (or DWORD) would be 32 bit. MS started to use these terms in VC++ simply to remove the confusion if an int is 16 or 32 bit long.

  24. #24

    Thread Starter
    Lively Member outcast24817's Avatar
    Join Date
    Nov 2004
    Location
    USA
    Posts
    122

    Re: C++ VS Visual Basic?

    lol, enabling the optomizations took off 1.8 seconds with the VB app
    **not completely learned**
    Complete control of the registry ~

  25. #25
    vbuggy krtxmrtz's Avatar
    Join Date
    May 2002
    Location
    In a probability cloud
    Posts
    5,573

    Re: C++ VS Visual Basic?

    Quote Originally Posted by Joacim Andersson
    I admit that when it comes to speed, you can write C++ programs that runs much faster then a VB program. But in many cases that just doesn't matter. For a regular desktop application, like a word processor, speed is not the main concern since your program will have more then enough time to process any input made by the user (what kind of computer runs slower then even the fastest of typewriters can type?).
    One thing worth mentioning is the gain C can achieve in some tasks involving processing a huge amount of data, like image processing, parsing text... Do you remember our recent cross-posts here when I badly needed help to write my own C dll's? That was definitely an example where you can incroporate some C to your VB project to really boost its the performance.
    Lottery is a tax on people who are bad at maths
    If only mosquitoes sucked fat instead of blood...
    To do is to be (Descartes). To be is to do (Sartre). To be do be do (Sinatra)

  26. #26
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: C++ VS Visual Basic?

    Quote Originally Posted by Joacim Andersson
    The C++ standard doesn't set the boundaries for an int or a long. An int is at least 16-bit in size. Word is not a new term, a word is a 16bit integer. A double word (or DWORD) would be 32 bit. MS started to use these terms in VC++ simply to remove the confusion if an int is 16 or 32 bit long.
    Well strictly speaking a "Word" is supposed to be as many bits as the processer, so on a 32-bit system a word is 32 bits long. A DWord therefore would be 64 bits. But in Windows a word is 16 bits and DWord 32 bits, for the same reason I suppose that an Integer in VB is 16 bits when it should really be 32 bits.

    Quote Originally Posted by outcast24817
    time it takes for c++ to count to 1000000000: 8.125 seconds
    time it takes for VB to count to 1000000000 : 19.203 seconds
    That's extremely slow. It took me about 1.8 seconds on average. Also, your test involves floating point numbers which is always going to slow down an app, C++ as well as VB. Here's the code I used (all the advanced optimisations were on):
    Code:
    Option Explicit
    Option Base 0
    Option Compare Binary
    
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    '
    
    Public Sub Main()
        Dim lngStartTime    As Long
        Dim lngFinishTime   As Long
        Dim lngMax          As Long
        Dim lngCounter      As Long
        
        lngMax = 1000000000
        
        lngStartTime = GetTickCount()
        
        While (lngCounter < lngMax)
            lngCounter = lngCounter + 1
        Wend
        
        lngFinishTime = GetTickCount()
        
        MsgBox "Time: " & lngFinishTime - lngStartTime
    End Sub
    Quote Originally Posted by outcast24817
    this was using my xp home anthlon 2800 (2. GHZ)(they cheated me of 800 Mhz! i am going to have to overclock)
    The point of that system is not that 2800 = 2.8GHz but rather an Athlon 2800 is approximately the same speed as a 2.8 GHz Intel. I'm using a 2600 myself.

    I tried making the same app in C++, it took approximately 2.5 seconds in debug mode (In the VB IDE I stopped it after a minute or so) but being a C++ n00b I couldn't get a message box to display the time taken, all it would say was "Time: " instead. I guess that's a point for the discussion, VB is a hell of a lot easier to learn than C++.

  27. #27

    Thread Starter
    Lively Member outcast24817's Avatar
    Join Date
    Nov 2004
    Location
    USA
    Posts
    122

    Re: C++ VS Visual Basic?

    what is the purpose of these two lines?
    Option Base 0
    Option Compare Binary

    and could you post your c++ code?
    **not completely learned**
    Complete control of the registry ~

  28. #28
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    Option Base 0 means that arrays lower bound is zero which is the default so that line doesn't really do anything. You could also set Option Base 1.

    Option Compare Binary is also a default setting meaning that functions like InStr and StrComp are case sensitive, "a" differs from "A". You can also set it to Option Compare Text.

  29. #29
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    Re: C++ VS Visual Basic?

    Quote Originally Posted by penagate
    ...but being a C++ n00b I couldn't get a message box to display the time taken, all it would say was "Time: " instead.


    Code:
    MessageBox(0, "My time was ****", "Finished", 0);


  30. #30
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: C++ VS Visual Basic?

    I know that NoteMe I just don't know how to concatanate strings

    Code:
    #include <iostream>
    #include <tchar.h>
    #include "windows.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
      // Count to 1000000000
    
      long  lngStartTime    = 0;
      long  lngTime         = 0;
      long  lngMax          = 0;
      long  lngCounter      = 0;
    
      lngMax = 1000000000;
    
      lngStartTime = GetTickCount();
    
      while (lngCounter < lngMax)
      {
        lngCounter++;
      }
    
      lngTime = (GetTickCount() - lngStartTime);
    
      MessageBox(0, (LPCTSTR) "Time: " + (lngTime), "Speed Test", MB_OK);
    
      return 0;
    }
    I know its wrong, it says "Time:" but nothing else.

  31. #31
    VB6, XHTML & CSS hobbyist Merri's Avatar
    Join Date
    Oct 2002
    Location
    Finland
    Posts
    6,654

    Re: C++ VS Visual Basic?

    I'm not sure as I did C++ in 2002 the last time, but it was something like:

    Code:
    String = concat("Time: %s", lngTime);
    I'm not sure if that is the command... concat was the first one to come in to mind for *cough* some reason *cough*.

  32. #32
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    It's strcat(s1, s2); s2 is added to s1. Just make sure s1 is large enough to contain s2 as well, C doesn't do it for you. This is a C function, but of course also exists in C++. However in C++ there is often a string class where the + sign have been overloaded so you can concat strings using the + sign. If the two strings are of this string class that is.
    Last edited by Joacim Andersson; Jun 18th, 2005 at 08:58 AM.

  33. #33
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: C++ VS Visual Basic?

    How you convert a long to a string? I tried type casting it but of course then it has to think it is a pointer and throws an exception.

  34. #34
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: C++ VS Visual Basic?

    Quote Originally Posted by outcast24817
    what i found disgusting was that i got an error for not capitalizing "GetTickCount" when making the C++ version of the program. I looked around and i couldnt find any option to turn case sensitivity off, (or make it like VB where it corrects all instances for you) does anyone know how to fiddle with this feature?
    C and C++ are case sensitive languages. long is not the same as LONG, etc.

  35. #35
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    Quote Originally Posted by penagate
    How you convert a long to a string? I tried type casting it but of course then it has to think it is a pointer and throws an exception.
    Use the _ltoa() function, or _itoa() to convert an int to a string.
    Code:
    char buff[20];
    long lng = 3497612L;
    
    _ltoa(lng, buff, 10); // 10 is the base, must be a value between 2 and 36
    You can also use _ltow() or _itow() for the Unicode versions of the functions.

  36. #36
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: C++ VS Visual Basic?

    Righty-oh, thanks for that

    I gave up trying to get it to work with strcat so here's what I got in the end
    Code:
    #include <iostream>
    #include <tchar.h>
    #include "windows.h"
    
    int _tmain(int argc, _TCHAR* argv[])
    {
    
      // Count to 1000000000
    
      long  lngStartTime  = 0;
      long  lngTime      = 0;
      long  lngMax      = 0;
      long  lngCounter    = 0;
    
      lngMax = 1000000000;
    
      lngStartTime = GetTickCount();
    
      while (lngCounter < lngMax)
      {
        lngCounter++;
      }
    
      lngTime = (GetTickCount() - lngStartTime);
    
      char msg[5];
      _ltoa(lngTime, msg, 10);
    
      MessageBox(0, (LPCTSTR) msg, "Speed Test", MB_OK);
    
      return 0;
    }
    In Debug configuration it clocked about 3.2 seconds and with full optimisations on it said 0 seconds everytime, even when I multiplied the maximum number by 10. This led me to think that the compiler had stripped out my loop as part of the optimisation process... So I played around with the optimisations... once it clocked 4.5s... and now I can't get any time at all no matter what I do

    So I still think C++ is faster, its compiler is definitely smarter, because there aren't many situations when you want a program to count one-by-one

  37. #37
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    Quote Originally Posted by penagate
    So I still think C++ is faster, its compiler is definitely smarter, because there aren't many situations when you want a program to count one-by-one
    Is there anyone who has ever claimed that C++ would be slower? How smart the compiler is has nothing to do with the language itself. There are many C++ compilers out there, some are better then others.

  38. #38
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: C++ VS Visual Basic?

    Let me rephrase that.

    "I still think C++ is definitely faster even though I couldn't actually get it to clock a time that was faster than I could achieve in Visual Basic."

    "The MS VC++ compiler is definitely smarter than the MS VB6 compiler because it stripped out an unnecessary piece of code which the VB compiler left in even with full optimisations enabled."

  39. #39
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: C++ VS Visual Basic?

    BASIC compilers usually don't cut of loops since it's a old habit in the BASIC language to add loops to do a pause. Stripping it off would render old code useless.

  40. #40
    MS SQL Powerposter szlamany's Avatar
    Join Date
    Mar 2004
    Location
    Connecticut
    Posts
    18,263

    Re: C++ VS Visual Basic?

    These conversations can be so pointless - faster compiler? More efficient object code?

    How about a good programmer vs a poor programmers - I bet that makes the biggest difference.

    I come from 25+ years of mainframe programming. We've been converting all our mainframe apps to VB with MS SQL for the past four years.

    We decided that all the business logic should be in T-SQL stored procedures - that's a "slow" language when compared to the likes of C++ or VB - I would imagine the crowd would say.

    Recently we took our scheduling algorithm - dozens of pages of mainframe code - that puts students into high school classes. Some kids schedule in a couple of dozen iterations - some take 3000 or 4000 or more iterations. The mainframe code was all about loading memory pools with data - so that the iterations would be liquid fast.

    For the past 4 years I had been suspicious that it would be required to be written in VB on the client - or C++ on the client - or C++ as an extended stored procedure on the SERVER.

    Well we actually wrote it in T-SQL in a STORED PROCEDURE on the SERVER. About 6 pages of queries - some serious logic. But it takes less then 5 minutes to schedule a large high school (1500+ kids). That time beats the mainframe. Written in a 4-th generatation language like T-SQL. I was blown away.

    Now we have an incredibly easy to support routine - basically a pile of queries in a package - that complete an incredibly complex task.

    Moral of the story - use the best tool for you to quickly create, easily support, easily enhance - basically produce more efficiently.

    Could this routine run faster in C++? Probably. Would it be worth it - from our business perspective - no.

    *** Read the sticky in the DB forum about how to get your question answered quickly!! ***

    Please remember to rate posts! Rate any post you find helpful - even in old threads! Use the link to the left - "Rate this Post".

    Some Informative Links:
    [ SQL Rules to Live By ] [ Reserved SQL keywords ] [ When to use INDEX HINTS! ] [ Passing Multi-item Parameters to STORED PROCEDURES ]
    [ Solution to non-domain Windows Authentication ] [ Crazy things we do to shrink log files ] [ SQL 2005 Features ] [ Loading Pictures from DB ]

    MS MVP 2006, 2007, 2008

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width