Hacker News new | past | comments | ask | show | jobs | submit login
Impressed By Slow Code (dadgum.com)
68 points by angusgr on May 2, 2011 | hide | past | favorite | 7 comments



A much better C standard library would help a lot into thinking at C code from an higher level point of view. Especially if you have easy to use data structures in form of a lib, it is really easy to resist to use a list and O(N) lookups just to type less code where an hash table is a better feet.

Why the C standard library does not get improved with a few data types like linked lists, hash tables, dynamic strings, and so forth is something I can't understand (one common reason why poorly written C code ends slower than equivalent code wrote in a scripting language is because of strlen() and other stupid string operations into a loop ending into exponential time complexity).


There have been attempts to provide a better standard library in plain C, and in fact these are fairly well available in operating systems. The problem is that no library spans all platforms.

On Unix systems with Gnome, there's GLib. It's very well-featured, very portable and available as prebuilt DLLs for Windows, at least.

On Mac OS X and iOS, there's CoreFoundation. My humble opinion is that it's the best OO-style C library. I'd love to use it on Windows, but unfortunately Apple wavered on their original commitment of open-sourcing CoreFoundation. They stopped releasing the source, and getting CF to build became very complicated at some point. I've lost track of what's the current situation, but clearly this makes it very difficult to rely on CF for cross-platform applications.


Resistance from embedded programmers, I gather. Don't forget that C crosses a huge number of platforms.

That said, BSD sys/tree.h (self-balancing trees) and sys/queue.h (linked lists of all kinds) give you a lot of functionality and can easily be made part of your project (be warned, though: glibc has a very incomplete implementation, so make sure to use the BSD version.)



"I've seen Python programs that ended up faster than C".

Yeah, there is nothing in c that makes it significant faster per se than python, remember python is pre-compiled.

C gives you control, it is "portable assembler" if you are used to assembler it is trivial to know exactly what the CPU does, if you can take advantage of it it will be faster, if you can't it wont.

With control you can make something run 100-1000 times faster because you know what the computer does, with a high level language you can not control it, period, it is abstracted.

That is the use of C or specific hardware(100-1000 less power usage).

Low level optimizations for a 10% speed up?. IMHO, Non sense.


A 10% time difference can make or break whether a video game truly feels real time. That's 54fps => 60fps.

If you mean "You typically get far more than a 10% return on low-level optimization investment," I agree. It's typically a dramatic improvement.


Maybe pypy or unladen swallow is pre-compiled, but CPython is interpreted as bytecode.

Could you give an example of python that's faster than C? Genuinely curious; I'd love to see one. (EDIT: wait I'm a noob, the article said that, not you. Sorry.)




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: