@karpathy/microgpt in the fastest compiled languages
The goal of this project is to benchmark the performance of Andrej Karpathy's microgpt in the fastest compiled languages. The same algorithm, same dataset, same hyperparameters (1000 steps, seed 42), but different languages. Currently, we have: C, C++, Go, Odin, Python, Rust, and Zig. Planned: Fortran, D, and Nim.
Python version is disabled by default, set it to True in the
bench.py, line 29 if you want to have it.
I was really surprised with Go's performance when I plugged in the custom Arena bump memory allocator I wrote for the C version. With it, Go matches Zig and Odin's performance. Without it, Go scored ~3 sec. I want to think that my Go version of microgpt is the fastest out there. If you have written a faster/better version or know who did, please let me know. Rust is all about unsafe code; the safe version I wrote initially performed at ~2 secs.
The only thing that I changed from the original Karpathy version was to make the build_topo function not use a map to detect visited values. This improved the performance dramatically.
The project is platform agnostic. It will create an isolated .venv and install all the Python dependencies.
Important: the project assumes you have C, C++, Go, Odin, Python, Rust, and Zig compilers installed; it will skip any that you do not have. It will not install them for you.
Use a simple command in the root of the folder:
python plot_benchmark.py --run-bench --showThis project is licensed under the MIT License — see the LICENSE file for details.