Learning about Rust Benchmarking with Sudoku from 5 minutes to 17 seconds

1 month ago 4

Bryson Meiling

Press enter or click to view image in full size

Ferris enjoys solving puzzle also

I’ll take you through the process of optimizing a Sudoku solver written in Rust. We’ll start with a simple, unoptimized version and apply a series of optimizations that will take the time to solve 100,000 puzzles from over 5 minutes down to just 33 seconds, and 20,000 of the hardest puzzles from over 2 minutes down to just 17 seconds.

Free Friend’s Link

The Setup

The project is a command-line Sudoku solver written in Rust. The puzzles are read from text files in the src/puzzle_banks directory, thanks to the github project Sudoku Exchange Puzzle Bank. Each line in these files represents a single puzzle in the following format:

0000847b216e 020900000048000031000063020009407003003080200400105600030570000250000180000006050 2.3

The second part of the line is the puzzle itself, where 0 represents an empty cell.

The basic flow of the program is:

  1. Read the puzzle file.
  2. For each line, parse the puzzle string into a Board struct.
  3. Call the solve function on the board.
  4. Print the statistics.

The Benchmarks

Read Entire Article