Haskell Is Faster Than C | Prime Reacts

preview_player
Показать описание
Recorded live on twitch, GET IN

MY MAIN YT CHANNEL: Has well edited engineering videos

Discord

Hey I am sponsored by Turso, an edge database. I think they are pretty neet. Give them a try for free and if you want you can get a decent amount off (the free tier is the best (better than planetscale or any other))
Рекомендации по теме
Комментарии
Автор

I really like how he gave no actual code where Haskell is faster than c

SpikeTaunt
Автор

Classic "C is slow because I don't know C" argument. Its like if I got into a formula 1 car, couldn't understand the 20 buttons on the steering wheel or how to even start it, and then decided "my Honda is way faster"

LusidDreaming
Автор

I thought Primes opinion that "<insert language> is faster than C if you cant write C" was far fetched but this guy literally confirmed it

bckends_
Автор

I like Haskell, but this take was insane. Saying that Haskell has faster data structures... writing pure functional data structures that are performant is really hard actually (Okasaki's Purely Functional Data Structures is an awesome book).

permutationlock
Автор

The OP is the definition of "skill issue" embodied. It's not hard to write data structures in C. Heck many books on data structures offer code written in C !

TheLouisEric
Автор

My ONLY gripe about the primeagen videos is he drops gold nuggets of knowledge in the most random times in the most random videos that when I want to look back and reference it I cannot find it. He'll make fun of VS C*de and say something wise on a video about runtime performance it is wild.

eej.
Автор

I love this guy's take:

"Well uh, if you are programming in the language that is notorious for having, like, 40 years worth of libraries, and you dont use the libraries, them maybe perharps haskell just wins, you know".

Some people have the craziest takes...

CEOofGameDev
Автор

That "linked lists as trees" illustration in Excalidraw was fantastic. You had me rolling!

ISKLEMMI
Автор

To say the Haskell is faster for bigger projects is such a Haskell programmer thing to say. Pure theory... noone actually did write it and more importantly, noone actually benchmarked it.

sarabwt
Автор

- Introduction: Haskell is competitive with C and can be faster in some benchmarks (0:00)
- Skill issue: The argument that X is faster than C is often due to the individual's skills in writing C code (0:30)
- Two advantages of Haskell that make it faster than C: optimization and use of better data and algorithms (1:01)
- Comparison to C: Many languages are slower than C, but benchmarks often use worst-case scenarios (1:34)
- Real-world performance: JavaScript's performance is not just about math equations, but also about object manipulation and validation (2:06)
- Performance differences: JavaScript's performance on non-multi-core machines is significantly impacted (2:37)
- Memory management: Higher-level languages like Haskell provide garbage collection and prevent memory leaks (3:09)
- Benefits of garbage collection: Garbage collector plus arenas allow better management of memory and improved performance (3:40)
- Haskell's performance: Haskell is often as fast as C or even faster in benchmarks (4:11)
- Advantage of Haskell: Haskell's compiler has more knowledge about the program, allowing for better optimization (5:13)
- Evaluation: Haskell's lazy evaluation allows the compiler to analyze and optimize code more effectively (6:46)
- Skill issue in optimization: Hand-tuning code for specific cases is challenging, but Haskell can do it naturally (7:16)
- Benefits of high-level languages: Higher-level languages provide easier development experiences and better data structures (8:09)
- Example: More complex data structures in Haskell can be more efficient than simple linked lists in C (11:23)
- Comparing languages: C is low-level, while higher-level languages provide better tools and data structure management (11:54)
- Unfair comparisons: Benchmark scenarios may restrict the usage of certain features, leading to biased results (13:25)
- Using threads in Java: Java's thread support gives it an advantage in certain benchmarks (18:40)
- Conclusion: Haskell provides a better development experience and allows for efficient data structure implementation (24:57)

furyzenblade
Автор

"Just as a little anecdote, I heard a story once" - ok, but my uncle Dave told me at BBQ that he knows a guy who writes Basic so fast it can beat C AND Haskell!!!!

simivb
Автор

I challenged him on a few claims and stances, and he basically said he was being controversial on purpose because he believes it's the best way to promote Haskell.

I'm more a fan of show, don't tell. Instead of telling people how great your language is, show them the text editor, IDE, game engine or desktop publishing program 🤷.

Now, there are a lot of optimizations Haskell does for free, but there are lots of basic optimizations C does that Haskell does not do, or optimizations that are theoretically possible you would expect Haskell to make but does not.

It's surprising how well it optimizes some things, and I can see lots of those finding their way into C++.

KeldonA
Автор

He claimed that Haskell is faster than C but the arguments he presented add up to Haskell being EASIER than C. No one would click on that video though. We’d all just say, “Yeah… no shit Sherlock.”

robertlowther
Автор

are we skipping over how he said C is a language for small fake problems?? that's ridiculous...Blender is like 90% C. also his whole argument about C people being too used to single thread to write good threaded code is crazy. I learned to use threads for the first time in C, and they were genuinely not that hard to wrap my head around once I understood the APIs for semaphores and mutexes.

alexhiatt
Автор

Everytime I hear "faster than C" I prepare myself for a good laugh 😂😂😂😂

iankaranja
Автор

13:33 - Or like in 90% of cases just use an array. It's faster, simpler and cache friendly.

VictorRodriguez-zpdo
Автор

It's easy to write fast Haskell? It's easy to write OK speed Haskell. Really fast Haskell can be gnarly as hell.

ur.kr.
Автор

The argument boils down to three factors:
- Haskell types gives the compiler more semantic knowledge so it can optimise a problem better when your code describes the problem well instead of describing what you want the generated code to do, which is what you need to do to write fast C.
- There are three ways to make program execution fast, you can defer work (do less work unless you truly need it), you can do work ahead of time, and you can find ways to do work in parallel. If your code consists of a lot of pure functions and your compiler can tell, then it can also automate some parallelisation of the code. C compilers usually have to analyse the intermediary representation to tell if there's parallelism to pull out, they don't have this semantic knowledge from the source. Haskell compiler knows from the start. Theoretically, it could also do the multithreading of a piece of code mechanically instead of having the code written for it specifically. Haskell can also defer work that a C program would do before if knows that it needs the result, because it uses a lazy evaluation scheme. However, this is a double edged sword, as Haskell tends to favour deferring work over doing it ahead of time, which can sometimes lead to huge amounts of work being deferred to badly timed execution places, so it's hard to write interactive or time sensitive code that has reliable timing characteristics. And for ahead of time calculation, Haskell can do more of it, and mostly the question is one of the horrible textual replacement C macro mechanism, but on the other hand, as stated before, Haskell tends to prefer to defer instead of doing work ahead of time, even if the best choice would be to do it at compile time.
- C simply requires the programmer to do more of the decision making and implementation themselves, while in Haskell the compiler can figure a lot of the nitty gritties out for the programmer without being to bad of a trade off.

All of these things in favour of Haskell are countered by a few advantages of C:
- Any C compiler has orders of magnitude more optimisation work behind it than the entire Haskell world.
- C is incredibly good at arrays, and Haskell is biased towards trees and lists. And there is no chance of better cache coherency than fixed size arrays.
- Haskell never takes the mutability path, C can build something in mutable steps and use mutable algorithms when they are beneficial.
- Haskell tends to prefer heap memory to stack memory.
- As long as you implement data structures yourself in C, do multithreading and parallelisation manually, and ensure correctness manually, there is nothing about Haskell that C doesn't do as well. The only thing Haskell fundamentally does better is handling strings, because C style strings are objectively worse than most other languages' strings.

liorean
Автор

The problem I have with the "skill issue" argument is that it goes all the way down. Technically you can write faster assembly than C; technically you can write Verilog that runs faster than x86-assembly-on-Intel-CPUs, and technically you can hand-design chips that run faster than that. At some point you really have to draw a line in complexity.

黃于軒-jo
Автор

This video is hilarious because I am LITERALLY writing an AVL tree in C (technically it's C++ but nothing here can't be done in C) for my DSA class.

captainfordo