Why is it so god damn fast?

Why is it so god damn fast?

Other urls found in this thread:

youtube.com/watch?v=mz5ODQCueP8
cs.cmu.edu/afs/cs/academic/class/15745-s02/www/lectures/lect1.pdf
leto.net/docs/C-optimization.php
beej.us/guide/bgnet/
github.com/purpasmart96/pmd_test/blob/master/src/common/stack_generic.c
blog.carlesmateo.com/2014/10/13/performance-of-several-languages/
twitter.com/NSFWRedditImage

Because it's a portable assembly language.

C = O(log2 n)
other languages = O(n!)

No garbage collector
No interpreter
No bytecode emulator
No bullshit

Only supports operations that real hardware supports.
Extremely minimal runtime.
Decades of compiler development.
Gives the compiler craploads of room to optimise, unlike many other languages.

That's very untrue and is just something perpetuated by people who don't know either C or asm.
Many reasons. People who care about performance put effort into the compilers which let's them optimize your code well.
C has undefined behavior that assists it in allowing the compiler more freedom for optimization.
People who write C code often care about performance.
C code is low level enough that failure to be fast is your fault. Meanwhile in other higher level languages you're not granted that control and have a lot of reliance on the compiler (or interpreter) to do the work for you. That excuses a lot of slow C programs as 'poorly written'. Where the corresponding program in another language would be fast or face the same excuse. Perhaps more clearly: if you write programs poorly because you're bad you should be using Java and it's JIT because it will help you write faster programs than you will manage in C.

It's not as fast as you think either. Even amateur programmers can read the disasm of a program and alter it to have it run faster. That's especially true in C++ as many optimization passes break down in the face of 'zero cost abstractions'.

You could write very high level languages with very poorly defined low-level details and have that run very fast. The problem is that you'll have a mess of undefined behavior (or equivalent) to deal with up at that high level.

>No stupid coders
You forgot the most important

There's stupid C programmers. They just suffer more and usually don't get anywhere.

>C
>fast
only with a lot of effort
try to sort a list

It's actually slower.

>That's very untrue and is just something perpetuated by people who don't know either C or asm.
I know both C and assembly very well.

this is the biggest reason. C is faster than, say, java, but the biggest problems are almost always algorithmic.

This

Then you know that it's by no means portable assembly. I guess you're asking me to call you a liar?
>nested loop test
Yeah I've seen you do this where you force the compiler to not eliminate dead code for C and then have the JIT do the very same thing at runtime a few thousand iterations in.
It's not a honest comparison.

There are a fuckload of stupid C programmers. And the worst part is, most of them are arrogant as shit.

only is some specific circumstances, but ya, people hate on java too much. it's actually optimized af now

>Then you know that it's by no means portable assembly. I guess you're asking me to call you a liar?
It is, and I'm actually calling you a liar. It has no constructs found in modern programming languages and offers a mere abstraction over assembly.

There's a reason why you only program C where you absolutely have to.

real question here:
Given I want to develop graphic applications for Android. What would be the best (highest performance/lowest battery drain/build size) way to do it?
opengl & Java
opengl & c++ using ndk
something else?

Please no 'game engines'

I remember that retarded benchmark. It was deeply flawed.

>Please no 'game engines'

Unreal Engine will be faster than anything you can produce yourself.

absolute highest?

opengl & c++ using ndk & a brain & shittons of time

if you only have half a brain or not enough time use opengl & java

>dat python forward inefficiency

CPython can't even support concurrency within the interpreter, it's not a language for performance full stop.

I know. I use Python and I like it very much. I just thought it was funny how it actually got slower from 2 to 3.

Java = O(1)

Indeed. It's a fantastic language, and I kind of like the fact that it just focuses on doing what it's good at instead of screwing around trying to be the next Java.

Hello I find this thread interesting however my thread watcher only notifies me when I get a (you). So if someone would kindly reply to me when someone posts something noteworthy and I can hop by and give a quick read.

Thank you in advance and have a nice day.

lolol i shared this sheep so you got a notification for no reason xDD

fuck YOU

youtube.com/watch?v=mz5ODQCueP8

...

POO

"C is fast." is a very stupid way to put it.
You can write slow code in every language.
Also Python is just as fast as C.

No, before you freak out, let me rephrase:
If you do EXACTLY THE SAME THINGS in C that you do in Python, they are the same speed.

So the choice is yours: Do I want to use a number class that does a lot of boundary checks, never overflows can cast itself into a string and much more? Than you would naturally use something like Python. But if you check your own boundaries and only need a simple a+b result, than Python doesn't allow you to do this. C does.

Also many people don't realize taht it's a lot about the compilers. Today compilers are very very mature and optimized., they are not a simple "C to assembly dictionary", they do a lot of very complicated things for you. If you write C or C++ today, compilers will most of the time produce faster code than you could if you wrote assembly yourself. That's because low level code optimization is hard and complex - unless we are talking about trivial tasks, of course.

You're describing C++ here. C is only low level crap an has no effective abstraction building mechanisms.

Because it's only a step above assembly

>It's not a honest comparison
What's dishonest about it? Sounds like you're just defensive that language implementors have found ways to beat out C.

But that's not what I was talking about, user.

See:
>cs.cmu.edu/afs/cs/academic/class/15745-s02/www/lectures/lect1.pdf

Or here:
>leto.net/docs/C-optimization.php


>" Most compilers have several levels of optimization. Make sure you're using the highest level. One popular compiler, gcc, has an incredible variety of optimization levels and options. Some compilers have special #pragmas or keywords (for example, inline) which also affect optimization.
>High levels of optimization can make poorly written (but compilable) code break. Less often, optimizers mangle perfectly correct code. Problems with side effects and evaluation order tend to screw things up, so you may have to fix the code up a little before you can use the highest level. Signal handlers activated at inopportune times may disturb an optimized program in ways that wouldn't disturb an unoptimized one."

>No stupid coders
You haven't met me then

I laughed for 20 seconds straight

i wouldn't even know where to begin to sort a list in C. It doesn't have any modules like python. You have to be a literal Rainman to even use it.

>i wouldn't even know where to begin to sort a list in C
And that is the problem with code monkeys.

>i copied some pajeets shitty sorting code from stackoverflow and it is slow

How can I write a http get request in C?

and it somehow ended up in the standard library

C standard library can't sort dynamically allocated data structures
Try again, pajeet

qsort you fucking faggot

write(socket, "GET ...", len);
read() to get the reply.

It doesn't wait for you to declare your gender, sexuality and political views. It just works disregarding the bullshit fads ruling over the normalfagosphere at any given time

What?
I don't care whether there is a standard function.

The problem is that there are people who are unable to sort a list at all in C.

float my_gender = 0.123343223242; //check your cis privilege int fags

You are an idiot
qsort() sorts contiguous data, not dynamically allocated data structures

PO(O)

beej.us/guide/bgnet/

this is the best programmer on earth.

decades of autistic optimization

have pointers to the data in contiguous memory

_Bool my_gender;

Is sorting a list really that hard of a problem for current programmers? Jesus...

I see you are progressive enough not to define it as a constant.

Apparently, I haven't really thought about it but it shouldn't be rocket science. I already worked a bit with lists in C, it's not that complicated.

>I'm retarded tho
Just say so.

>CPython can't even support concurrency within the interpreter
you don't know what the fuck you're talking about

>sorting a list
are you retarded?

or try libcurl library

bool my_gender = 0.123343223242;
Why does this throw errors but still compile irl?

Yeah, with infinite constant.

>brainlet cant handle a simple list sort in C

Why wouldn't it compile? Think about how a float is stored in binary, then think about how a bool is stored in binary.

Manual memory control (no GC)
No gigantic library of imports (Everything is tailored to the specific application)
Pointer manipulation (No unnecessary copy-by-value moves)

>no u
Try harder faggot

Because it's close to the metal.

Because everything is done at compile time, no unnecessary overhead.
Here is some neat preprocessor tricks for True generics in C
github.com/purpasmart96/pmd_test/blob/master/src/common/stack_generic.c

>has no effective abstraction building mechanisms

>what are typedefs?
>what are callbacks?
>what are structs?

You're making yourself a fool.

>C has no useless bloat to slow it down
ftfy

Coercion?

lol bash what a failure of a language.

Luajit is amazing though. For a high level scripting language it gets comparable results on most benchmarks to low level languages. In some cases it can even be faster because it can take statistics on running code and optimize it even further. The author is a fucking genius and I'm surprised the language isn't more popular.

You are confusing c with embedded c

What is your assembly flavor of choice, user? x86, perhaps?

>If you do EXACTLY THE SAME THINGS in C that you do in Python, they are the same speed.
That's wonderful if the things you need to do are things that Python allows.

This is not all things.

Boi you haven't heard of Cython ?????

Agreed, pointers filter out the riff raff.

Sure, there is no reason to program in C if you're an dumb brainlet.

Do a test user. Write a basic C program and replicate it in Cython.

gotta go fast

>java, go and lua faster than assembly
Someone explain how this test is not horseshit.

Oh, and I found the source for your nested loop test. I'm not 100% but I've seen this and it might be the exact instance I'm talking about. It's a very clearly tuned circumstance for a JIT as you'll easily remove the loop and just do the math.
blog.carlesmateo.com/2014/10/13/performance-of-several-languages/

Not representative of real world performance. Unless this is the exact thing you're doing (trivial operations in many many loops).
It's hard to tell if he's aware of how misleading he is or if he's just blissfully ignorant.
I didn't feel your post worth responding to at the time but I find that unfair now.
See above. We don't actually care what nested loop performance is when you minimize the actual work (as we've done this ridiculous sum here). We care when we have a realistic workload.
What could be an interesting test is to see where Java JIT does its dead code elimination and where it does the naive transformation C has done (by necessity for reasons that'd take time to elaborate on).
Have the inner loop be a function call that does the same thing. Have it be a recursive call. Have it be a more advanced math function like a matrix multiplication.
I'd be interested to see the results. It'd give a good perspective on the usefulness of this JIT optimization. Which may be massive, and it may BTFO of C in many realistic circumstances. But from this we can't tell at all.

Because it's not a useful workload. See As I mentioned before for any 'nested loop test' a JIT has a massive advantage. I'm surprised it's such a minor difference actually. I think that aspect of this test might be tuned too. If you multiply the iteration sizes here C will just race off into the heat death of the universe while the JITs will do similarly well.

A way to view this is that the code for this algorithm is terrible. What we should do is multiply instead of looping. JIT can figure this out at runtime and C can't do that.

Because it's powered by jQuery.

It's not really that fast compared to Forth.

because C is simply a raw memory language with syntactic sugar

HERE YA GO :3

I really like this picture user. Mind if I save it?

>will do similarly well
Should. They have the information to decide to be fast anyway.

SHURE, WHY DONT CHA GO RIGHT AHEAD AN DO THAT, user! C:

Thank