Project 1999

Project 1999 (/forums/index.php)
-   Rants and Flames (/forums/forumdisplay.php?f=30)
-   -   C vs. C++ vs. C# (/forums/showthread.php?t=77377)

Lucky 06-22-2012 09:48 PM

C vs. C++ vs. C#
 
Hi. I am a computer scientist. This is a comparison of memory usage for a simple hello world application between C, C++, and C#. Compiled VS2010 32-bit x86 Release.

PHP Code:

// C#
// 1,968k
using System;

namespace 
hellonet
{
    class 
Program
    
{
        static 
void Main(string[] args)
        {
            
System.Console.Write("hello world");
            
System.Console.ReadKey();
        }
    }


PHP Code:

// C++
// 640k
#include <iostream>

int main(int argccharargv[])
{
    
std::cout << "hello world";
    
std::cin.get();
    return 
0;


PHP Code:

// C
// 484k
#include <stdio.h>

int main(int argccharargv[])
{
    
printf("hello world");
    
getchar();
    return 
0;


As you can see, C# uses 5x as much memory as C and 3x more than C++ just for a simple hello world application. And M$ is writing Windows.Next kernel in this managed language.

Rogean you can thank me for the adsense money from the future googlers that will find this site (as applies to all of my insights made here).

Lucky 06-22-2012 09:59 PM

Note: I was using the MS C compiler for the C code. Bjarne Strassoup (creator of C++) said that hello world should generate literally same code. So I copied the C code and compiled with MS C++ compiler and it was 488k.

interdasting

Razdeline 06-22-2012 10:09 PM

c++ for obv~ reasons

Lubian 06-22-2012 11:39 PM

I'm kind of wondering why you're comparing the memory usage of each of these Hello World programs in the different languages; is that supposed to be a way to determine which language is better? God, I hope not.

Furthermore, what also saddens me is your leap from this into the Windows 8 Kernel and managed, but I have a feeling you don't know what managed means.

Also, since you used "using System;" so you don't have to write the namespace System before Console. ReadKey() probably doesn't do what you think it does; I think your intention would be Read().

Lastly, you don't have to wonder if they generate the same code, since you can view the disassembly very easily in VS2010, but ensure you're viewing the release build when you do so.

Lucky 06-22-2012 11:50 PM

Of course I knew there would be criticism of comparing hello world applications, but I sincerely doubt C# will perform any better when dealing with generic containers compared to C++ STL which inlines to C.

Perhaps it is unfair as .NET is a framework, so I will compare it to Qt.

PHP Code:

// Qt C++
// 960k
#include <QtCore/QCoreApplication>

int main(int argcchar *argv[])
{
    
QCoreApplication a(argcargv);

    
std::cout << "hello world";
    
std::cin.get();
    
    return 
a.exec();


I didn't say anything about Windows 8.

Quote:

Originally Posted by Wiki
Midori is the code name for a managed code operating system being developed by Microsoft Research. It has been reported[1][2] to be a possible commercial implementation of the Singularity operating system, a research project started in 2003 to build a highly-dependable operating system in which the kernel, device drivers, and applications are all written in managed code. Microsoft has mapped out several possible migration paths from Windows to Midori (referred to as "Windows.Next").[5][6][7]

The namespace was unnecessary I'll agree, but not something which would have effected the compiler. From my understanding, ReadKey() is more-o'er-less similar to a single getchar() and std.cin() beyond the fact that return doesn't need to be pressed.

Lubian 06-23-2012 12:32 AM

Quote:

Originally Posted by Lucky (Post 671521)
Of course I knew there would be criticism of comparing hello world applications, but I sincerely doubt C# will perform any better when dealing with generic containers compared to C++ STL which inlines to C.

Performance wise, probably every developer knows that the lower level C languages are going to be faster than C#. It's also pretty widely known that the simple C# programs use more memory, because they purposely didn't design for an empty exe; since if you needed something with a low memory footprint or something time critical you would use a lower level language. This should be of no surprise for anyone who knows what a high level or low level programming language is and the advantages and disadvantages between the two.

Quote:

Originally Posted by Lucky (Post 671521)
The namespace was unnecessary I'll agree, but not something which would have effected the compiler. From my understanding, ReadKey() is more-o'er-less similar to a single getchar() and std.cin() beyond the fact that return doesn't need to be pressed.

I'm starting to think it's a waste of time even responding to you. You can clearly see the return type of ReadKey() from the IDE (it's a struct). I don't know why you would continue spewing misinformation after someone told you it might have been wrong, and the fact that it takes 1 second to validate.

I'll stop wasting my time here. Good luck with your thread and checking how much memory Hello World programs use in different languages.

Spectre 06-23-2012 01:01 AM

I could write a C++ program that could kill your whole family.

Lucky 06-23-2012 01:55 AM

As far as ReadKey() goes, it is the accepted practice of preventing a console application of immediately closing. I tried Read(), and of course there wasn't any significant difference in the memory footprint. Maybe they load similar buffers, or don't load any until the key is actually pressed and the method returns, that I do not know.

What inspired this in the 1st place was reading this statement on stackoverflow: The .Net framework takes anywhere from 5-15 megabytes of RAM just to load up enough code to execute "Hello World".

Obviously C# was going to fail in this. It's JIT'ed, which means that it's an inefficient waste of crap language designed solely for the purpose of treating ignorant software programmers as fodder for applications developed on a Microsoft platform. I don't care how easy it is to program in; there's no way in hell I'll use a language which doesn't put forth the idea of "flexibility" and "control" as important. C# was designed to make Microsoft money, and to provide businesses the ability to write generic, lame, CRUD applications.

But after seeing all of this I'm reaffirmed and glad I switched to Qt years ago and never looked back.

somnia 06-23-2012 03:09 AM

Hi. I am a developer. This is the reality check.

Taken from http://www.ecma-international.org/pu...T/Ecma-334.pdf referenced by http://en.wikipedia.org/wiki/C_Sharp...ote-ECMA-334-6.

As the definition of C# evolved, the goals used in its design were as follows:

• C# is intended to be a simple, modern, general-purpose, object-oriented programming language.
• The language, and implementations thereof, should provide support for software engineering principles
such as strong type checking, array bounds checking, detection of attempts to use uninitialized variables,
and automatic garbage collection. Software robustness, durability, and programmer productivity are
important.
• The language is intended for use in developing software components suitable for deployment in
distributed environments.
• Source code portability is very important, as is programmer portability, especially for those
programmers already familiar with C and C++.
• Support for internationalization is very important.
• C# is intended to be suitable for writing applications for both hosted and embedded systems, ranging
from the very large that use sophisticated operating systems, down to the very small having dedicated
functions.
Although C# applications are intended to be economical with regard to memory and processing power
requirements, the language was not intended to compete directly on performance and size with C or
assembly language.


I've bolded the most important bullet point for your reference. I understand many of you machine-hybrid basement dwellers enjoy ultra efficiency as I employ a number of you for highly specialized tasks in my company but keep in mind that it is important to use the right tool for the job.

Lucky 06-23-2012 03:17 AM

hence why it sux


All times are GMT -4. The time now is 08:36 PM.

Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.