Live data from Hacker News

The "C is Efficient" Language Fallacy

scienceblogs.com

81–90 of 127 posts

Re: The "C is Efficient" Language Fallacy

#81
In most cases manually cooked food is much cheaper and more healthy than purchased one, if you can cook. The same is correct for C/C++ programming in terms of execution speed and resource usage if you have knowledge and experience.

btw, JVM is mere a c++ code.

Re: The "C is Efficient" Language Fallacy

#83
post #78
post #10

Earlier quoted context omitted.

DSP is one domain where performance of a tiny part of the code (say 1%) is far, far more important than everything else. If you need to apply a filter to remove high frequencies, or if you need a Fourier transform, no high-level tuning or special algorithm will cut it: you need the filter or the transform, even if it's very costly. The bottleneck is real and unavoidable. I work in data acquisition and in this domain…

In this thread people are closely tying C/C++. Is objective-c in the same league?

No. Objective C isn't performance oriented, and while it's fine for most desktop apps (!) it's not in the same league as C++. C++ can actually let you use higher level structures that are faster than in C or Objective C because of template meta programming, as shown in the Blitz template library for numerical computation.

http://www.oonumerics.org/blitz/ This is what Templates are made for. And this is what you can't do in something like Java or Objective C. Java Generics boiling down to type cast at run time to and from Object, it doesn't help performance a bit.

Re: The "C is Efficient" Language Fallacy

#84
post #3

This argument is as old as the hills. It's probably true in a lot of niche situations. But the fact is, most C code is faster than higher-level language code, because: * C programmers have more freedom to arrange data in memory to exploit locality * C data structures need less bookkeeping * C programs manage memory manually, and so lack GC overhead * C programs can easily swap in different allocators for different wo…

A competent C programmer can clearly make a good, performant program in 10klines. A genius programmer, maybe 100klines.

There's something beyond those figures, though. And it gets worse when a team is involved.

The higher the level of the language rises, the less it allows making bad programs, however big the program is.

Re: The "C is Efficient" Language Fallacy

#85
post #19

Earlier quoted context omitted.

Right. C is a power tool. You can use it to create something blindingly fast. You can also use it to create something dog slow. I've seen Smalltalk programs outperform C programs. I know of an instance where a coworker benchmarked a C implementation of a block cipher vs. a Smalltalk implementation, and the Smalltalk ran 3% faster. Why? Naive manual memory management in the C implementation.

Another classic HLL vs. C argument: the anecdotal slow C program. Clearly, of these, there are many great examples. Unfortunately, it's a crappy argument, because there are also a zillion incredibly slow HLL programs.

That is a false dilemma tho'. No-one in the Python world has anything invested in a 100% Python solution to anything. Doing the compute-intensive bits in C is in fact expected and encouraged! The same is true in the Tcl camp. Maybe some HLL communities (Java?) like to be "pure" but I've not ever encountered that.

Re: The "C is Efficient" Language Fallacy

#86
post #52

C works in CUDA and OpenCL - which for scientific programming is the fastest thing there is. The GPU is used with C. C isn't faster than hand coded assembler on cpus... but is pretty damn quick. There are specialist compilers for C, like vector C etc. anyway... whatever. back to typing text into a file now.

CUDA and OpenCL have C syntax, but they are not C.

Re: The "C is Efficient" Language Fallacy

#87
post #85
post #19

Earlier quoted context omitted.

Another classic HLL vs. C argument: the anecdotal slow C program. Clearly, of these, there are many great examples. Unfortunately, it's a crappy argument, because there are also a zillion incredibly slow HLL programs.

That is a false dilemma tho'. No-one in the Python world has anything invested in a 100% Python solution to anything. Doing the compute-intensive bits in C is in fact expected and encouraged! The same is true in the Tcl camp. Maybe some HLL communities (Java?) like to be "pure" but I've not ever encountered that.

I agree. I like writing my goop in Ruby. But that's not what the article is about.

Re: The "C is Efficient" Language Fallacy

#88
post #83
post #78

Earlier quoted context omitted.

In this thread people are closely tying C/C++. Is objective-c in the same league?

No. Objective C isn't performance oriented, and while it's fine for most desktop apps (!) it's not in the same league as C++. C++ can actually let you use higher level structures that are faster than in C or Objective C because of template meta programming, as shown in the Blitz template library for numerical computation. http://www.oonumerics.org/blitz/ This is what Templates are made for. And this is what you can't…

[deleted]

Re: The "C is Efficient" Language Fallacy

#89
post #3

This argument is as old as the hills. It's probably true in a lot of niche situations. But the fact is, most C code is faster than higher-level language code, because: * C programmers have more freedom to arrange data in memory to exploit locality * C data structures need less bookkeeping * C programs manage memory manually, and so lack GC overhead * C programs can easily swap in different allocators for different wo…

[deleted]

Re: The "C is Efficient" Language Fallacy

#90
post #76

Earlier quoted context omitted.

C programs manage memory manually, and so lack GC overhead At this point, GC is often faster than manual allocation. (Due to being able to allocate or deallocate a bunch of things at once, rather than having to allocate/free memory whenever the programmer says to.)

You too are committing the fallacy of assuming that "managing memory manually" means using malloc() and free(). Fast programs don't use malloc() directly. Hell, even apr programs have standardized on this optimization. Many GC schemes are probably faster than malloc. But it's a much less credible argument to say that you have a GC that is faster than a custom allocator tuned to a workset. You probably don't.

Naive use of the GC is probably faster than any off-the-shelf manual memory management strategy. How many programmer hours are you prepared to pay for to get the last 1% of speed?
Post reply on HN