5 ms·
Yes, I think coming from C++, Rust is a more compelling language than Go. However, the Rust type system is a bit more complicated than the Go type system. Go
by KMag 14y ago
Yes, I think coming from C++, Rust is a more compelling language than Go. However, the Rust type system is a bit more complicated than the Go type system.
Go provides much better static guarantees and much better speed than Python/Ruby/JavaScript, without having to spend any time learning about the type system. However, Go's weaker type system doesn't appeal to a lot of people used to more powerful type systems.
- MatthewPhillips 14y ago> Go provides ... much better speed than Python/Ruby/JavaScript, Citation?
- wting 14y agoNo citation needed as long as you understand both languages' runtime stack. Python is an interpreted language that runs on top of a virtual machine (usually CPython). Types are determined at run time. .py -> .pyo* (bytecode) -> VM -> OS On the other hand, Go (and other C languages) have a different runtime stack: .go -> binary* -> OS Between source and binary are a bunch of compiler steps[0], but * is where both binaries are executed. Statically compiled languages do not have to determine types at runtime and therefore are able to optimize code paths much better. Still don't believe me? Here's a Fibonacci calculation micro benchmark[1] I ran: ╭─ting@noa /tmp/fib ‹python-2.7.3› ‹ruby-1.9.3› ╰─➤ time ./go 1346269 real 0.02s user 0.01s sys 0.00s ╭─ting@noa /tmp/fib ‹python-2.7.3› ‹ruby-1.9.3› ╰─➤ time python3 ./fib.py 1346269 real 0.61s user 0.60s sys 0.00s Sidenote: Java runs on a virtual machine (JVM) but it's performance comes very close to C languages due to static typing, JIT compilation, and heavy investment in the JVM from many companies. [0]: For C, compilation goes through these steps: hello.c (preprocessor) hello.tmp (compiler) hello.s (assembler) hello.o (linker) hello <-- binary to run [1]: https://gist.github.com/wting/77c9742fa1169179235f https://gist.github.com/wting/77c9742fa1169179235f
- dilap 14y agoDynamically-typed languages can be fast when run with a jit -- for example, Lua+luajit is close to Go in your microbenchmark. On my computer, for n=40, Go is 0m2.156s and luajit is 0m3.199s.
- wting 14y ago"Fast" and "close" are subjective terms. That's a 50% increase for a few thousand function calls. PyPy uses JIT to improve Python run time speeds but it's still magnitudes slower than statically typed languages. I've upped n to 40 and rerun with the following languages: C: 0.38s Java: 0.55s Go: 0.90s Rust: 1.29s LuaJit: 2.19s Haskell: 8.97s PyPy: 10.06s Lua: 22.87s Ruby: 22.13s Python2: 43.88s Python3: 66.28s All code is available in the previous mentioned gist: https://gist.github.com/wting/77c9742fa1169179235f https://gist.github.com/wting/77c9742fa1169179235f
- cygwin98 14y agoCan't imagine Ruby is twice as fast as Python 2 and three times as fast as Python 3 right now. Can you share your code in a gist?
- smosher 14y agoI'm curious what times you get with an iterative version, or at least using a LUT. As-is, this mostly benchmarks the stack (admittedly that is an interesting datapoint.)
- dilap 14y agoThanks for the extra results. Obviously, a single micro-benchmark will only take you so far (and something like the Computer Language Shootout gets you farther -- it's a shame and mystifying (to me) that that site no longer has results for LuaJIT...). But anyway, in my (limited) experimentations with LuaJIT, it's often been within a factor of 2x-3x of speed of C, which to me is pretty fast, and typical of many statically-typed, compiled languages.
- 14y ago