Python vs Numba vs c++: Different implementations of a sudoku solver!
Time (microseconds) | |
---|---|
Rust | 17 |
c++ | 31 |
Numba | 170 |
Java | 225 |
LuaJit | 283 |
CPython | 4000 |
pypy | 18000 (why?) |
The CPython algorithm was written first. This implementation uses recursion to solve the board. Running the CPython implementation using pypy actually resulted in longer runtime... To implement the numba version recursion had to be eliminated as it is not supported. This required changing the algorithm. The C++ implementation uses the non-recursive algorithm to make it easier to write. To achieve the highest speed the highest optimization had to be used. Unoptimized C++ took 110 microseconds, while the optimized took only 31. The java implementation was taken from an exercise I had in school a year ago.
pip install -r requirements.txt
g++ ccudoku.cc -o ccudoku -Ofast
javac judoku.java
then run with
java judoku
luajit ludoku.lua