8 ms·
Which programming language or compiler is faster
- adamddev1 5y agoCan anyone explain why C++ beats out C so clearly?
- mwattsun 5y agoI was curious too and found this: https://stackoverflow.com/questions/2513741/c-vs-c-for-performance-in-memory-allocation https://stackoverflow.com/questions/2513741/c-vs-c-for-perfo... from which I gather that if you're using an allocator function that zero's out memory then it will be slower of course.
- khoobid_shoma 5y agoI think the C code in the benchmarks are not really efficient. An experienced C programmer does not simulate C++ style memory management if speed matters.
- dorinlazar 5y agoC++ is just a stricter C - if you write proper C, it will be a correct C++ program, therefore it would run at the same speed. There's no way C can be other than marginally faster than C++ - if you write C and compile it with a C++ compiler. Then you have various optimizations that come from things like templates, constexpr. Look at the qsort method - to have a modicum of genericity you need to pass a function that will be invoked. Instead, a C++ version would be able to be optimized to compare the elements directly, without calling a function, avoiding a big number of function calls. There's no way to make C faster than well written C++. But C++ is complex and a lot of people write bad C++, that's why it has developed a bad reputation. It's really undeserved.
- ReleaseCandidat 5y ago> There's no way C can be other than marginally faster than C++ In theory `restrict` (to disallow pointer aliasing like in Fortran) could lead to optimization gains, same as not having exceptions (the possibility of exceptions prohibits certain optimizations of the C++ compiler).
- dorinlazar 5y agoI agree; of course, both clang and gcc extend C++ with __restrict__ if I remember correctly; from what I know, there are more things that can be done in C++ to improve over C than the other way around.
- khoobid_shoma 5y agoIIRC, __restrict__ in clang and g++ does nothing when you write C++ code. It is there just for compatibility with C.
- ReleaseCandidat 5y agoThere is no reason, the fasted C++ code is actually C - I really don't know why somebody wrote that as C++. https://github.com/hanabi1224/Programming-Language-Benchmarks/blob/main/bench/algorithm/spectral-norm/8.cpp https://github.com/hanabi1224/Programming-Language-Benchmark... https://github.com/hanabi1224/Programming-Language-Benchmarks/blob/main/bench/algorithm/spectral-norm/7.cpp https://github.com/hanabi1224/Programming-Language-Benchmark...
- sdfdf4434r34r 5y agoBecause it's not C++ code: https://github.com/hanabi1224/Programming-Language-Benchmarks/blob/main/bench/algorithm/spectral-norm/8.cpp https://github.com/hanabi1224/Programming-Language-Benchmark...
- Jeff_Brown 5y agoWhat matters to me is incremental build time. Rarely do I compule a big program in its entirety from scratch. I don't use Unison but I would love to for this reason.
- anchpop 5y agounison cheats at this by being interpreted, if it weren’t it would have the same build times as everyone else (I suppose caching would be better in some cases, but i’m not sure if they’d be much better than what you get with nix?)
- wglb 5y agoSbcl compiles itself in just a couple of minutes.
- adenozine 5y agoI've always enjoyed seeing how it build its components faster and faster during the bootstrap. One of those simple joys of the make process.
- vlovich123 5y agoWebpack clean: 3 minutes Incremental: 700ms Esbuild clean: 100ms
- elcritch 5y agoThe title is a bit misleading. Its not clear if the compiler times are included, but the numbers do include the benchmark. Thats why the exact same sbcl compiler has different times. The benchmarks are mixed with some having simd and some using threads. It'd be helpful to be able to sort submissions by threaded/unthreaded as well. Still kinda fun to read the different languages. I found Zig was very chatty and annoying to read even compared to the C versions. The common lisp was foreign. The Fortran 90 with openmp and Julia versions were pleasant to read. The Nim version was easy to read but lacks threading or simd.
- deleted 5y ago
- clmay 5y agoI've been meaning to write a new frontend for the Computer Language Benchmarks Game that allows comparison of arbitrary pairings for a few years now and never got 'round to it. It's about time someone did. Thank you and nice work!
- superjan 5y agoThis is a really strange benchmark to use. Compiler speed is not an issue for these 100ish line standalone benchmarks. The question is how fast it is for a million-line project or worse. I doubt c or c++ do good there with their header file includes for dependencies.
- celeritascelery 5y agoI am sure if someone contributed a million line project for every language they would be happy to benchmark it.
- Shish2k 5y agoI’m working on it :) https://github.com/shish/rosettaboy https://github.com/shish/rosettaboy (Ok it’s 5-10k lines rather than a million, but it’s non-trivial enough that the differences between languages are noticable)
- subb 5y agoOn a single core processor, obviously not, but massive C++ codebase are compiled with multicore CPU, and often distributed. The advantage of the header inclusion model is you get an bunch of independent compilation units, and so it's straight forward to parallelize. A common way to speed things up even more is to merge some cpp file together, so each compiler thread is active for longer and common headers are compiled once. With the new module feature of C++20, compilation is transformed into a DAG, and it is still unclear if it's really faster than just throwing a lot of cores at the problem.
- unnouinceput 5y agoYou show me that IDE for C++ who is using those multicore CPU's for compilation who's faster than Delphi, for same number of lines and/or external dependencies. Btw, Delphi is still using 32 bits for its IDE and a single core and still blows out of the water anything else in terms of millions of lines of code compilation time.
- deleted 5y ago[deleted]
- silvanocerza 5y agoThe faster programming language or compiler is the one you use. Always.
- nobleach 5y ago...I wish this were true. I'm back writing JavaScript/Typescript. The new build tools are great. Perhaps in the new year I'll convert some of these repos to build with esbuild or swc... or vite.
- nouveaux 5y agoNo matter how good you are at Python, if you need to build an SPA, it'll be far faster to go with Javascript. This is true even if you have to learn Javascript from scratch. If you're an expert at Pascal, good luck trying to use it on the Arduino. The hardest part of learning a second and third programming language is overcoming your own frustration. Yes there are some pretty gnarly concepts in languages like Haskell. However, most mainstream programming languages are very similar to each other.
- benibela 5y ago>If you're an expert at Pascal, good luck trying to use it on the Arduino. It is supposed to work with FreePascal: https://wiki.freepascal.org/AVR_Programming https://wiki.freepascal.org/AVR_Programming
- keithnz 5y agoThis is almost never the criteria people use as it is often not that important. Productivity is often a bigger factor. Security and Robustness is another factor. Libraries is another, portability, Platform limitations, Domain problem to be solved. Most software these days isn't really constrained by speed, if the software ran 10x faster, you'd only get marginal gains.
- sigjuice 5y agoWhat does it even mean for a language to be faster?
- mottosso 5y agoThat the same logical steps expressed in one language results in less computation time spent - when compiled or interpreted - than when expressed in another language. Seems a resaonable question to ask, given there's more to a language than how you express things. Like toolchain, library availability and community.
- retrac 5y agoSame idea as comparing different compilers for the same language. Some algorithms can be expressed in some languages in an essentially identical way. For example, various sorting algorithms look pretty much the same in Fortran, Pascal and C. Only surface syntax differs. Assuming this is done fairly with each implementation being properly equivalent, it's a way to compare the speed of the languages, at least for that algorithm.
- fhd2 5y agoNot sure how technically accurate it is, but "language" usually implies more than just the syntax. I hear and say things like "compiled language", "interpreted language", "language VM", "garbage collected language", "dynamically typed language" and so on. Those things all say something about development speed and runtime speed.
- sigjuice 5y agoThe phrases "compiled language" and "interpreted language", despite their widespread use, are not particularly sound concepts. There are plenty of languages that have both compilers and interpreters.
- coldtea 5y agoA lot. Semantics that can be made fast (e.g. C vs Python) with little effort. (Some languages with bad semantics for that might still get fast, but the language itself isn't designed to help that. JS for example was made fast, but with tons of effort but with tons of money and man-centuries thrown in by Google, Apple, Mozilla, MS, not the kind of recources available to most languages. So, I'd call a language whose semantics afford optimization a fast language). Runtime complexity (e.g. "zero overhead" vs "lotsa overhead" features). Also, I find the "language vs compiler" dicthotomy pedantic and tedious. For most languages and most use cases, there's a single dominant canonical version, e.g. CPython, Matz's Ruby, Oracle's Java. Just because there are niche other implementations all 10 people use doesn't change the fact that 90% of users will be on the canonical implementation, and for them, THAT's synonymous with the language, not just some abstract spec.
- peanut_worm 5y agoJulia always seems to rank #1 or close to it when compared to other interpreted languages but I only ever see it used for research and math. Why doesn’t anyone use it for anything else?
- Narishma 5y agoIts ridiculously large memory usage might be a reason.
- dunefox 5y agoMemory is cheap. Between large memory usage and slow code, I'd rather have the first. Also, that has never stopped Java from being used.
- fault1 5y agoa lot of it is stuff its runtime loads by default, like huge BLAS buffers, the llvm orc and such. I think there have been steps recently to make those optional recently. Julia was really optimized for "big iron"-styles of workloads, but that's less than ideal when you are not trying to just do linear algebra all day.
- _dain_ 5y agoI think founder effects. It started in the math and science community so that's where most of the library-writing energy has gone into.
- ludamad 5y agoI think it competes with R, which has a similar usage profile
- g42gregory 5y agoLack of integration with other massive libraries that Python, Java and C++ have. Lack of books, tutorials and extensive knowledge bases that Python, Java and C++ have.
- 5y ago
- bernardv 5y agoThose are two very different questions.
- rjsw 5y agoNot very impressed with those Lisp benchmarks that I examined.
- dybber 5y agoNot the Ocaml ones either. Not sure this makes for a fair comparison.
- nurettin 5y agoI wonder where FPC stands. Original Pascal implementations were single pass and I've had Mloc delphi projects build in seconds.
- cmroanirgo 5y agoI came here to ask the same. Pascal files are laid out in such a manner that the "implementation" section of the file is ready for compilation to bytes and any forward references just mean that it's code ends up later in the exe. Typical runtime speed has only ever been fractionally slower than c/c++.
- medo-bear 5y agoCommon Lisp (sbcl) performance via native implementation of simd [0] is very impressive ! It is litteraly acheieving C/Cpp speeds (within few ms). Great work by Marco Heisig [0] https://github.com/marcoheisig/sb-simd https://github.com/marcoheisig/sb-simd
- inshadows 5y agoThere used to be http://shootout.alioth.debian.org http://shootout.alioth.debian.org and it crashed and data was lost AFAR. There's now https://benchmarksgame-team.pages.debian.net/benchmarksgame/index.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... https://en.wikipedia.org/wiki/The_Computer_Language_Benchmarks_Game https://en.wikipedia.org/wiki/The_Computer_Language_Benchmar... Just wanted to mention prior art.
- igouy 5y agoIn 2018 Debian Alioth hosting service reached EOL. The same benchmarks game project moved to new hosting at: https://benchmarksgame-team.pages.debian.net/benchmarksgame/index.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- savant_penguin 5y agoWhat makes zig so memory efficient?
- coldtea 5y agoManual memory management a la C, and easy access to custom allocation (arenas, etc) that usually aren't used in most C code (and C doesn't offer as allocators by default). Add compile time processing which can get pretty far into reducing all kinds of otherwise runtime ops...
- Narishma 5y agoWhy link to that particular problem and not one of the dozen other in that page?
- btdmaster 5y agoI wonder if guile[1][2] would be competitive to the other Lisp (Scheme) implementations. It was significantly faster than Python at numerical tasks in my experience. [1] https://www.gnu.org/software/guile/ https://www.gnu.org/software/guile/ [2] https://web-artanis.com/scheme.html https://web-artanis.com/scheme.html
- debesyla 5y agoI wonder why wasn't PHP included? It is still very popular in websites... Is it somehow not comparable/not worth to compare?
- igouy 5y agoPerhaps suggest PHP to the website author. Meanwhile — https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/php.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- winrid 5y agoThis compares single and multithreaded solutions... doing these kinds of comparisons is hard but that seems silly.
- igouy 5y agoDon't you want to know what the performance difference is? Don't you have the opportunity to compare user time as-well-as wall clock time? ( The benchmarks game does provide that sort --https://benchmarksgame-team.pages.debian.net/benchmarksgame/performance/spectralnorm-cpu.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... )
- winrid 5y agoAh, thanks.
- hdjjhhvvhga 5y agoWhoah, I'm shocked by seeing Julia perform well. The compile times back in the day were abysmal. I mean even for very, very simple projects you had to wait for dozens of seconds. It looks like they made an enormous progress there.