C is ssssslooooowing me

This is a discussion on C is ssssslooooowing me within the C Programming forums, part of the General Programming Boards category; Hi all, I am using C on purpose but it is slower than say java to develop code in C. ...

  1. #1
    Big & Little Wong Tin-Bar Jackie Chan's Avatar
    Join Date
    May 2008
    Location
    Hong Kong
    Posts
    23

    C is ssssslooooowing me

    Hi all,
    I am using C on purpose but it is slower than say java to develop code in C. However i think that if I write my code in C it will be the fastest. May be only assembly can beat C in speed. I think C is also faster than C++.

    So I need some positive feedback saying that C will be indeed fastest. So I can continue the slow paced development in C.


  2. #2
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    I'd rather go with C++. It can be as fast as C, depending on what you do, although it may be a bit slower. However, it is also much faster and advantageous to develop in for most applications over C. I don't think the speed hit compared to C really matters (it's nowhere as slow as java or dotNet, etc).
    But yes, C is faster than other languages, but also the hardest. Remember that C means a lot of security issues unless you develop good code and take extra care not to run into any security issues.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  3. #3
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    It would be easier to develop code in C++. It MAY be slower (depends which compiler you use...on a decent one the speed should be almost identical). C is definately faster than Java, VB, VB.net, C# and any other interpreted language. You should be more worried about how much faster it is, rather than it just being faster.

  4. #4
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    507
    Quote Originally Posted by Elysia View Post
    I'd rather go with C++. It can be as fast as C, depending on what you do, although it may be a bit slower. However, it is also much faster and advantageous to develop in for most applications over C. I don't think the speed hit compared to C really matters (it's nowhere as slow as java or dotNet, etc).
    But yes, C is faster than other languages, but also the hardest. Remember that C means a lot of security issues unless you develop good code and take extra care not to run into any security issues.
    Some have the opinion that Java is better than C++ in terms of speed.
    Not everything that can be counted counts, and not everything that counts can be counted
    - Albert Einstein.


    No programming language is perfect. There is not even a single best language; there are only languages well suited or perhaps poorly suited for particular purposes.
    - Herbert Mayer

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Some of the C++ tests would not compile. I've never been very good at decoding GCC's error messages, so if I couldn't fix a test with a trivial modification, I didn't include it in my benchmarks.
    *poof*, There goes his credability.

    Not to mention it was only level 2 optimization
    g++ [test].cpp -O2 -march=i386 -o [test]-386
    While javac will optimize as much as it can.

    See http://zi.fi/shootout/ for a response to that benchmark
    Last edited by zacs7; 05-26-2008 at 02:29 AM.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    22,269
    Some have the opinion that Java is better than C++ in terms of speed.
    I know another fellow who has shown that PHP beats Java in terms of speed in a specific benchmark

    To properly answer Jackie Chan's question, we need to know what he is developing, since only then we can help to guage which language is the appropriate tool for the job.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    Not to mention that some of the tests are needlessly complicated. The methcall example doesn't even need a virtual destructor.
    C/C++'s efficiency also comes with the flexibility. Just stuff some code in there and it's sure to be slow.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,308
    Quote Originally Posted by stevesmithx View Post
    Some have the opinion that Java is better than C++ in terms of speed.
    Don't trust the info on that page. It's written by a java programmer that doesn't know what they're doing with respect to C++. They tend to use dynamic memory allocation for stuff that no sane C++ programmer would use dynamic memory allocation for. When the code was changed to allocate on the stack instead, then the test ran so fast that the timing didn't even register above zero.
    Not to mention they used a pretty old C++ compiler and didn't use the best optimisation settings either.
    If you want the real story then the page below runs the same code on a newer compiler, with a few fairness changes, and gets results with C++ easily outperforming java by a factor of two or three.

    In Summary some will always be wrong.

    C or C++ are only faster because they're lower level though. With lower level programming comes more responsibility and more ways to shoot yourself in the foot. Don't feel you have to port your code to C or C++ unless it is definitely too slow. Even then, ask some java gurus for help first too.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    Big & Little Wong Tin-Bar Jackie Chan's Avatar
    Join Date
    May 2008
    Location
    Hong Kong
    Posts
    23

    Thanks all.

    I think C is faster since it is very low level and that is why it is taking longer to develope something. But may be it will help me learn more. My only worry is people may not be using it any more for new projects. There may be only old maintained code in C.

  10. #10
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    C++ can be as fast as C and is much easier to use. And you shouldn't be that worried about performance C vs C++, because you'll not notice it. C++ can deliver blazing speeds, as well.
    C is necessary when it comes to the real resource lacking environments that cannot support C++ or where it is even more necessary for full speed.
    C will give you a headache in big projects, but with C++ it's manageable.

    Anyway, what are your plans? What do you intend to do?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Big & Little Wong Tin-Bar Jackie Chan's Avatar
    Join Date
    May 2008
    Location
    Hong Kong
    Posts
    23
    Quote Originally Posted by Elysia View Post
    C++ can be as fast as C and is much easier to use. And you shouldn't be that worried about performance C vs C++, because you'll not notice it. C++ can deliver blazing speeds, as well.
    That said I never noticed speed difference between C and Perl either.

    C is necessary when it comes to the real resource lacking environments that cannot support C++ or where it is even more necessary for full speed.
    C will give you a headache in big projects, but with C++ it's manageable.
    Well no such thing as resource lacking though I have 1.5GHz, 512MB,20GB configuration. After huge language base of Perl and complexity of Java the C is like a refresher. So little to learn and understand. And after that just stay awake while coding.

    Anyway, what are your plans? What do you intend to do?
    Plans?

  12. #12
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    23,012
    Quote Originally Posted by Jackie Chan View Post
    That said I never noticed speed difference between C and Perl either.
    Well, it all matters how you use it and for what task. Certainly, a GUI app can be just as fast in both C/C++ and Perl. But for very intensive tasks, C/C++ will almost certainly be better, but yes... it just goes to show you aren't limited to the fastest but most complex language.

    Well no such thing as resource lacking though I have 1.5GHz, 512MB,20GB configuration. After huge language base of Perl and complexity of Java the C is like a refresher. So little to learn and understand. And after that just stay awake while coding.
    Indeed.
    If you want complexity, then I would say C++ is a dream for you. The amount of complexity it can amount to in incredible. It can become far more complex than C, even.
    But you know, computers, having a lot of resources and all, you can use almost any language you see fit.

    Plans?
    Well, what are you trying to do? Web? GUI? Games? Etc?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  13. #13
    Big & Little Wong Tin-Bar Jackie Chan's Avatar
    Join Date
    May 2008
    Location
    Hong Kong
    Posts
    23
    Quote Originally Posted by Elysia View Post
    Well, what are you trying to do? Web? GUI? Games? Etc?
    GTK is ugly. GTK+ is for C++. I can try with WinAPI. But it is very scary as for now.
    I can only write CGI using C. may be I will try that too for Web.
    I will try to write games using OpenGL+SDL (both C libs).
    In short all of the above and more.

  14. #14
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > GTK+ is for C++
    GTK+ is a C library. It's for C, C++, Perl, PHP (there are tonnes of bindings)

    > I will try to write games using OpenGL+SDL (both C libs).
    Yes, but C++ is a superset of C. You should be able to use most C libs with C++. Not to mention there are many bindings of OpenGL & SDL to other langauges.

    I've done everything in your list before, all in C. Some things I longed for C++, or perl -- sometimes even PHP. I like Java, although I don't love it. Choose the language for the job, not one language for all jobs. You don't build a house with just a hammer do you?

  15. #15
    Registered User
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    217
    I would go with C++. I started with C and changed to C++ a while ago.

Page 1 of 4 1234 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21