Fast Racket - racket/racket GitHub Wiki
The performance of Racket programs is usually faster than equivalent Python programs and compares favorably with other languages in the same category. For mode details see The Computer Language Benchmarks Game page.
The performance of an individual program will depend both on the chosen algorithms data structures and the Racket environment in which it is run:
- choose an appropriate algorithm and data structure for your program.
- run your program using
racket
from the command line. Non-interactive mode should be used instead of the REPL to benefit from the module system. - consider using
raco make
to reduce startup time on subsequent runs - use
#lang racket/base
(andrequire
all necessary modules) instead of#lang racket
, as this may lower the amount of code that is loaded overall. - consider using Typed Racket if your application uses a lot of mathematical calculation.
- consider using
future
orplace
for parts of your application that are parallelizable. - use the FFI to run performance sensitive parts of your application in C or C++. E.g., flomat lets you call out to BLAS and LAPACK from standard Racket.
When writing your program
-
make use of the profiler in DrRacket to better understand the performance of your code.
-
make DrRacket perform more like
racket
by using theChoose Language...
dialogShow Details
panel to;- disable debugging & profiling.
- disable
Preserve stacktrace
(checkbox).
-
Profile parallel programs with
future
using the the futures visualizer graphical profiling tool.
When evaluating the performance of your own Racket programs please be aware of the following caveats:
- Student Languages are aimed at providing help for students and have extra
debugging enabled. Port your code to
#lang racket
for a speed boost. - Programs run inside DrRacket, have debugging enabled by default. This will provide better error reporting, but programs will run slower.
For more details on Racket Performance, Virtual Machine Implementations, byte code, machine code, and Just-in-Time (JIT) Compilers see the Performance Chapter in the Racket Guide and more information about compilation.
Miscellaneous:
- There's a compiler rule that inlines local functions if they are used only once. This doesn't apply to module-scope functions however.
- If you want to know how long your code takes to run, rather than how long racket takes to start you should use
time
(docs link)