Skip to content

Python vs Numba vs C++ vs Java: Performance of different implementations of a sudoku solver!

Notifications You must be signed in to change notification settings

ridulfo/Sudoku-solver-implementations

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku-solver-implementations

Python vs Numba vs c++: Different implementations of a sudoku solver!

Performance

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.

To run the python implementation, install the requirements using:

pip install -r requirements.txt

To run the C++ implementation, compile it using:

g++ ccudoku.cc -o ccudoku -Ofast

To run the Java implementation, compile it using:

javac judoku.java then run with java judoku

To run the Lua implementation:

luajit ludoku.lua