Why is C slow?

Discussion in 'Computer Science & Culture' started by pluto2, Nov 4, 2009.

Thread Status:
Not open for further replies.
  1. pluto2 Banned Valued Senior Member

    Messages:
    1,085
    Why is the C language slow?
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. Crunchy Cat F-in' *meow* baby!!! Valued Senior Member

    Messages:
    8,423
    Why do you think its slow?
     
  4. Google AdSense Guest Advertisement



    to hide all adverts.
  5. John99 Banned Banned

    Messages:
    22,046
    because the code isnt optimized at runtime.
     
  6. Google AdSense Guest Advertisement



    to hide all adverts.
  7. pluto2 Banned Valued Senior Member

    Messages:
    1,085
    It is often said that C is slower than other languages like C++. I want to know why that is.
     
  8. Crunchy Cat F-in' *meow* baby!!! Valued Senior Member

    Messages:
    8,423
    uh... what?
     
  9. Crunchy Cat F-in' *meow* baby!!! Valued Senior Member

    Messages:
    8,423
    I think you're asking the wrong question. The real question is why are your "sources who often say this" saying this?
     
  10. CheskiChips Banned Banned

    Messages:
    3,538
    C is slower. I think it's because of its construction...it was really before a lot of modern object oriented programming and complex modular algorithm utilization.

    1. It doesn't throw out its excess data...and if it's programmed incorrectly can have a very clear and distinguishable memory leak.

    2. Syntax is limited, for example no subs exist to determine ranges and programming them can lead to variations in effectiveness.

    3. To modify an arrays values you have to individually modify each value which can be time consuming.

    4. But most of all the thing that reduces speed is.....No coroutines...at least that's what I imagine is the root of the cause. The entire program has to run linearly and so you never get multi-threads or classes running independently. Because of this it reduces program stability and causes all elements of the program to be postponed for further use until every single would-be thread has finished its processing commands.
     
  11. Crunchy Cat F-in' *meow* baby!!! Valued Senior Member

    Messages:
    8,423
    Do you have some kind of stats that show this?

    You do realize that anything in C++ can be modeled in C right (regardless of how visually awkward it might be)? What does this have to do with speed?

    Wait what? C++ doesn't throw out its excess data and can have memory leaks as well. What does this have to do with speed?

    What's a "sub"?

    I can only assume you are talking about assigning a single value across a block of memory. Why not use memcpy() / memset()?

    You do realize C has threading right? _beginthread().

    What? Are you seriously trying to say that single threaded applications are less stable?

    See last two comments.
     
  12. CheskiChips Banned Banned

    Messages:
    3,538
    No, it's my experience.

    C++ pre-programmed subroutines are optimized...if you not the optimization technique for every C equivalent then it's identical. Most don't.

    Could be, I didn't know that if they do. Most of my programming experience is in J++, I thought it was an added benefit.

    I meant to say, no command line...I was going to write subroutine...because a lot of those functions in J++ are in the library.

    I mean doing function F to array[] y for every val from 0 to n. To do this in C you have to construct a for loop.

    Nope.

    Less stable in the sense...if one thread in a multi threaded software app throws an exception that crashes the thread...its data can be held redundantly in other threads...meaning you don't need a full re-initialization. Whereas a single threaded program throwing an exception and crashing needs to be completely re-initialized.



    Your experience in C programming is likely to be more extensive than mine, I've always heard its slower because of its lack of functions as compared to new codes. Such that its resultant software map is irregular and prone to instability when trying to mimick modern languages.
     
  13. Crunchy Cat F-in' *meow* baby!!! Valued Senior Member

    Messages:
    8,423
    How did you experience the slowness?

    C pre-programmed subroutines are also optimized. I'm not sure what you're getting at.

    It's not a possibility. It simply is. C/C++ and J++ are consequently worlds apart.

    Ok, if I replace the word "sub" with "command line" in your original statement then I still don't quite know what you're talking about.

    A for loop isn't any less fast than a c++ STL functor. They both get broken down to the same assembly.

    Now you know; hence, that aspect of the argument is invalid.

    In a parallel processing environment that is true (up until the point that so many threads die that you have a memory/resource leak that kills the app/OS). In general, adding additional threads adds complexity. More complexity == more risk that something will go wrong... and it will.


    I am not sure what you mean by "new codes"; however, it would lack sheer number of functions as compared to c++ classes/functions (simply because there are more in c++). I am not sure how that makes C slower though. I am also not sure what the point of comparing C to modern languages is because this thread isn't about that. If you wanted to compare however, I bet that the average C application would perform 20 times better than say a java app. That's just the reality of building on top of infrastructure.
     
  14. RubiksMaster Real eyes realize real lies Registered Senior Member

    Messages:
    1,646
    If C is slow, it's because of optimization, not language features. No matter what language you are writing in, it all has to be converted to machine code at some point. It all depends how this is done.

    I bet if you tried to write a large program in assembly, you would complain it was slow, simply because it's difficult to write optimized code by hand, when you're at that low of a level. It's not the language itself that's slow, it's the programmer or the compiler failing to optimize.

    That's what the compiler will do anyway. Your CPU is a sequential piece of machinery.


    Way more complexity. It's surprising how few programmers actually have a good grasp of concurrent programming.
     
  15. superstring01 Moderator

    Messages:
    12,110
    It's ancient, for starters.

    ~String
     
  16. CheskiChips Banned Banned

    Messages:
    3,538
    Well, you both clearly know more about programming than I do. I'll simply capitulate.
     
Thread Status:
Not open for further replies.

Share This Page