4 ms·
edit: weirder, naive Julia (1.7 on Linux) is terrible. 45 KB/s. Ruby is slightly slower than Python or Rust, 11 MB/s. I was expecting Python to be slowest amon
by yodelshady 5y ago
edit: weirder, naive Julia (1.7 on Linux) is terrible. 45 KB/s.
Ruby is slightly slower than Python or Rust, 11 MB/s. I was expecting Python to be slowest among the interpreted languages, apparently not. Pypy yields a speedup to 70 MB/s.
Summing naive implementations (for each i: start with empty string, append fizz/buzz based on the modulus of each, then conditionally append i and print):
Julia 45 KB/s
Ruby 11 MB/s
CPython 15 MB/s
Rust 16 MB/s
Pypy 70 MB/s
C 160 MB/s
- sc11 5y agoDo you mind sharing the Julia code? Seems odd that it's that far away from even Python.
- adgjlsfhk1 5y agoby default Julia uses locking for writes to guarantee thread safety when multiple writes are happening. That said, it's totally possible to go way faster using buffered IO.
- yodelshady 5y ago``` for i = 1:typemax(UInt64) s = "" if i % 3 == 0 s = s * "fizz" end if i % 5 == 0 s = s * "buzz" end if s == "" s = string(i) end println(s) end ``` Measured over 10 s after a 10 s burn-in period, Julia 1.7 on Ubuntu 21.10.
- Qem 5y agoI think recent versions of Ruby include a optional JIT compiler. Did you try it?