6 ms·
I liked it many years ago but when I noticed how slow and heavy my code was I left it. It manages to be slower than Python. Perhaps the Chez Scheme rewrite help
by brabel 11mo ago
I liked it many years ago but when I noticed how slow and heavy my code was I left it. It manages to be slower than Python. Perhaps the Chez Scheme rewrite helped with that but now if I need a Lisp I have Common Lisp which is super fast and lightweight enough.
- gus_massa 11mo agoIt's usually faster than Python for numeric stuff, and has a similar speed for strings. See for example https://benchmarksgame-team.pages.debian.net/benchmarksgame/index.html https://benchmarksgame-team.pages.debian.net/benchmarksgame/... But if you run the code inside the default IDE call DrRacket, you must go to the menu Language>Choose_Language... then click "Show_Details" and disable "Debugging". With debugging enabled, you get nicer error messages, but it blocks a lot of optimizations and the program get slow.
- igouy 11mo agoSee for example https://benchmarksgame-team.pages.debian.net/benchmarksgame/box-plot-summary-charts.html#chart-fastest-more https://benchmarksgame-team.pages.debian.net/benchmarksgame/...
- ashton314 11mo agoThese are small benchmarks, so don’t over-generalize from this data point alone, but Racket absolutely crushes Python in terms of speed and goes speedily enough against other popular performance-focused languages: https://lambdaland.org/posts/2023-12-20_functional_langauge_speed/ https://lambdaland.org/posts/2023-12-20_functional_langauge_... https://lambdaland.org/posts/2024-09-27_threaded_interpreter/ https://lambdaland.org/posts/2024-09-27_threaded_interpreter... Matthew Flatt, the Racket lead, says that Racket’s performance should be fairly comparable to Java, much faster than Python, slower than Julia/Rust/etc. That’s been a helpful model for me: if Java is fast enough, Racket will do fine.
- gus_massa 11mo agoNice examples! With a few tricks, I made the Racket program x5 faster. I think you tried to use the simplest program, so I tried to add as few cheats as possible. I added a happy path for fixnums and keep the slow path in case the iterations gets too big: (define (count-collatz n [cnt 1]) (if (fixnum? n) (cond [(= n 1) cnt] #;[(zero? (unsafe-fxremainder n 2)) (count-collatz (unsafe-fxquotient n 2) (+ 1 cnt))] [(zero? (fxand n 1)) (count-collatz (unsafe-fxquotient n 2) (+ 1 cnt))] [else (count-collatz (+ (* 3 n) 1) (+ 1 cnt))]) (cond [(= n 1) cnt] [(even? n) (count-collatz (/ n 2) (+ 1 cnt))] [else (count-collatz (+ (* 3 n) 1) (+ 1 cnt))]))) My program has two versions, the version with `fxand` is slightly faster than the versions with `fxremainder`. I have to used two `unsafe-` functions, but a smart enough optimizer should have fixed them. So I'm adding this example to my wishlist. I think it would be very hard for the optimizer would be to replace `/` with `quotient`, but the rest look possible.
- pjmlp 11mo agoI wonder how, given that anything that brings Python and performance together, usually means it is actually C code, or similar, as PyPy is seldom reached for. Raket is compiled, thus maybe not the right build parameters?