-2

I know very little about what makes a language "fast", but it stands to reason for me that a language designed for extreme minimalism would also be extremely fast, right?

C is far closer to English than BrainFuck, and the compiler size for BrainFuck is remarkably small at 1024 bytes, almost nothing compared to the Tiny C Compiler, which is sized at around 100 KB.

However, all the websites online treat C as the fastest language bar bytecode or assembly.

(Clarity edit to take question off hold)

If I made the same program in C and BrainFuck (which, for example, calculated the first 100 numbers of the fibonacci sequence) , which one will complete the task faster at runtime? Which one would compile faster?

  • 4
    Once the program is compiled, it doesn't matter what the original source code looked like. It's just machine code. – Barmar Jun 27 '19 at 09:34
  • Barmar so why is C considered the "fastest language" compared to other compiled languages like C# and Java? – ipsa scientia potestas Jun 27 '19 at 09:36
  • 2
    Why is C faster than C# and Java? Google it. Volumes have been written on C's design goals, what makes it fast, why low-level languages are faster than higher-level ones, and so on. – John Kugelman Jun 27 '19 at 09:37
  • 3
    "*but it stands to reason for me that a language designed for extreme minimalism would also be extremely fast, right?*" No. If anything, having versatility in its low-level operations is going to allow the language to be faster. For instance, in Brainfuck there is no built-in multiplication, so if you want to do `10000*10000` you need a loop that adds those up 10000 times. Obviously that's going to slow it down a lot. Heck, there's no addition either, so you need a loop for that, too. So even multiplying two numbers in the billions will take a long time already. – Blaze Jun 27 '19 at 09:39
  • There is no standard for BF, but the C standard says that the compiler can produce any program that just has the same observable behaviour as the C program in the C abstract machine. If we consider BF to be allowed to do the same, i.e. the observable behaviour is that of `.` and `,`, then it is just a matter of implementation quality - C can be as fast or as slow as BF. – Antti Haapala -- Слава Україні Jun 27 '19 at 12:04
  • Usually _iterpretive_ languages have faster, smaller, compilers. But you pay for it in execution seed. Check the definition of "byte code"; it does not mean what you think it means. – Rick James Aug 26 '19 at 01:22
  • Depends on what it is implemented, if it is implemented in C, it's either as fast or slower –  Oct 08 '19 at 18:14

2 Answers2

5

Yes and no. There are language features that will make a language slower (in some cases garbage collection, dynamic types only known at runtime, …) and others that will make it more complex but allow the compiler more freedom.

Case in point: the constexpr keyword of C++ is somewhat complex to implement, but allows the programmer to tell the compiler "This function application has to be replaceable by its result". In extreme cases, this allows the compiler to replace costly function calls (e.g. a fast fourier transform) with a constant result without any runtime cost.

Compiled C code is very fast, because it has almost no features that don't map down directly to assembler and it has almost half a century of compiler optimizations.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
tstenner
  • 10,080
  • 10
  • 57
  • 92
2

It depends on the ability of the compiler.

A compiler converts a source file into an executable. There are four phases (for a C) program to become an executable:

  • Pre-processing
  • Compilation
  • Assembly
  • Linking

An abstract syntax tree (AST) is usually created. The AST is often used to generate an intermediate representation (IR), sometimes called an intermediate language, for the code generation.

This intermediate language is actually compiled to machine code and it does not matter, from which high level language (in this sense brainfuck a high level language) you got this from.

schorsch312
  • 5,553
  • 5
  • 28
  • 57