aboutsummaryrefslogtreecommitdiff
path: root/benchmarks/benchmarks.md
blob: 148ce1d103ef6b5817f6979074957f0ec89b39ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# Benchmarks for the H48 optimal solver and comparison with vcube

This page contains some benchmarks for some of the possible
configurations of the H48 optimal solver. For comparison we also
include similar measurements for two other optimal solvers:

* Andrew Skalski's [vcube](https://github.com/Voltara/vcube) (commit
  9f5bc2c), which is a truly impressive implementation of Tomas Rokicki's 
  [nxopt](https://github.com/rokicki/cube20src/blob/master/nxopt.md)
  that has been taken as a reference throughout the development of H48.
  This solver also uses an A* search, but the search is supported
  by different pruning tables.
* Arhan Chaudhary's
  [egg-solver](https://github.com/ArhanChaudhary/egg-solver) (commit
  ed726e2), which is an AI-generated implementation of the H48 method
  with highly-optimized microthreading.

Similar benchmarks can be found:

* In Chen Shuang's
  [dedicated github page](https://github.com/cs0x7f/cube_solver_test/wiki),
  which includes many more solvers. At the time of writing, the version
  of H48 used for these benchmarks is a rather old one. Note that
  cube48opt is a re-implementation of the H48 solver by Chen Shuang.
* In Enrico Tenuti's [thesis](https://github.com/enricotenuti/h48thesis),
  also using an old implementation of H48, but including more data and
  nice plots.
* In [the documentation page](https://egg-solver.arhan.sh/docs/index.html)
  for egg-solver.

## Setting

*All movecounts are in Half Turn Metric*

For the benchmarks we used some sets of random positions that can be found
in `benchmarks/scrambles`. We divide them by optimal solution length,
because the time to solve a scramble grows exponentially on the number of
moves, so mixing up positions with long and short solutions is going to
make the shorter solution almost irrelevant. Even within the same solution
length the time to solve a random position can vary significantly,
so we have used sets of 25 scrambles and taken the average of those,
except for the [Superflip](https://en.wikipedia.org/wiki/Superflip),
which is a single scramble.

For short solutions, the very low numbers we get with the largest solver
may be particularly inaccurate, because writing the solution (together
with some log messages) to standard output may take a significant portion
of the time, depending on the terminal emulator used and other factors.

All benchmark tests were done on the following configuration:

* CPU: AMD Ryzen 7 7700 (8 cores, 16 virtual threads)
* Memory: 2x Corsair Vengeance 32GB 5600MHz
* Motherboard: Gigabyte B650M K
* Operating system: Debian 13 (Linux kernel 6.12)
* Compilers: GCC 14.2.0 for H48, Chhang 19.1.7 for vcube and
  cargo 1.99.1 for egg-solver

## Benchmark results

### Single solution, single thread

The first test we performed was finding a single optimal solution, and
we compared the results with vcube.

This test was run in a single-thread configuration, because the three
solvers use very different strategies for multithreading: vcube can only
parallelize by solving one cube per thread, while H48 and egg-solver can
take advantage of multiple threads even when solving a single cube.
Therefore we prefer to compare their single-threaded performance only.

Since the size of the pruning table used by the solver is of utmost
importance, we include two statistics: time per cube and time per cube
*adjusted by table size*.  The adjustment we took simply consists in
multiplying the time per cube by the size of the table. Empirically this
leads to more even results across the board, although the speed of the
solvers of the same family does not scale exactly linearly with the size
of the pruning table.

<!-- The following details block can be found in benchmarks/tables_1_thread.md -->
<details><summary>Results: Single solution, single thread</summary>

Time per cube (in seconds, lower is better).

|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|
|:-----|:---|-------:|-------:|-------:|-------:|--------:|
|vcube 212 |58.2 GiB|    0.11|    0.75|    3.43|   27.28|    19.30|
|egg h11   |58.0 GiB|    0.01|    0.06|    0.24|    2.13|     0.14|
|H48 h11   |56.5 GiB|    0.08|    0.41|    1.80|   11.96|    15.28|
|vcube 404 |31.8 GiB|    0.23|    1.24|    6.10|   59.33|   268.26|
|egg h10   |29.0 GiB|    0.02|    0.10|    0.45|    3.96|     0.24|
|H48 h10   |28.3 GiB|    0.12|    0.69|    3.31|   24.85|    38.18|
|vcube 308 |21.2 GiB|    0.17|    1.02|    6.20|   58.70|   604.35|
|egg h9    |14.5 GiB|    0.03|    0.18|    0.87|        |         |
|H48 h9    |14.1 GiB|    0.22|    1.43|    6.53|        |         |
|vcube 208 | 7.3 GiB|    0.56|    4.36|   20.58|        |         |
|egg h8    | 7.2 GiB|    0.06|    0.36|    1.64|        |         |
|H48 h8    | 7.1 GiB|    0.46|    3.41|   14.23|        |         |
|egg h7    | 3.6 GiB|    0.10|    0.74|    4.00|        |         |
|H48 h7    | 3.5 GiB|    0.63|    4.87|   23.39|        |         |
|vcube 112 | 2.4 GiB|    0.96|    9.29|   40.52|        |         |
|egg h6    | 1.8 GiB|    0.18|    1.40|    7.69|        |         |
|H48 h6    | 1.8 GiB|    1.26|    9.47|   46.81|        |         |

Time per cube adjusted for table size (in seconds \* GiB, lower is better).

|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|
|:-----|:---|-------:|-------:|-------:|-------:|--------:|
|vcube 212 |58.2 GiB|    6.43|   43.80|  199.38| 1587.43|  1122.73|
|egg h11   |58.0 GiB|    0.55|    3.30|   14.11|  123.79|     7.94|
|H48 h11   |56.5 GiB|    4.31|   23.34|  101.61|  675.65|   863.48|
|vcube 404 |31.8 GiB|    7.40|   39.47|  194.01| 1887.94|  8535.87|
|egg h10   |29.0 GiB|    0.49|    2.84|   12.91|  114.83|     6.92|
|H48 h10   |28.3 GiB|    3.50|   19.36|   93.65|  702.04|  1078.64|
|vcube 308 |21.2 GiB|    3.51|   21.71|  131.50| 1245.26| 12819.94|
|egg h9    |14.5 GiB|    0.46|    2.64|   12.61|        |         |
|H48 h9    |14.1 GiB|    3.10|   20.21|   92.31|        |         |
|vcube 208 | 7.3 GiB|    4.08|   31.74|  149.68|        |         |
|egg h8    | 7.2 GiB|    0.44|    2.62|   11.88|        |         |
|H48 h8    | 7.1 GiB|    3.22|   24.11|  100.55|        |         |
|egg h7    | 3.6 GiB|    0.36|    2.69|   14.48|        |         |
|H48 h7    | 3.5 GiB|    2.23|   17.22|   82.63|        |         |
|vcube 112 | 2.4 GiB|    2.33|   22.53|   98.23|        |         |
|egg h6    | 1.8 GiB|    0.33|    2.54|   13.94|        |         |
|H48 h6    | 1.8 GiB|    2.23|   16.75|   82.75|        |         |

<img src="img/17moves1thread.png">
<img src="img/18moves1thread.png">
<img src="img/19moves1thread.png">
<img src="img/20moves1thread.png">
</details>

As we can see, egg-solver is the clear winner, consistently beating H48 by
factors of 5x-9x for all sets of scrambles, comparing tables of similar
size. Moreover, egg-solver is more than 100 times faster when solving the
superflip configuration, likely due to better expoitation of symmetries,
including inverse positions.

Adjusting for table size, H48 is generally faster than vcube. The gap between
the two solvers is larger for scrambles with longer optimal solutions.

### Single solution, multiple threads

The same benchmark as before is repeated using 4 and 16 threads (recall
that the CPU used for these tests has 8 physical cores and 16 virtual
threads).

For the reasons mentioned above, in this section we will only compare H48
and egg-solver; for the latter with enable per-cube parallelization using
the `-c 1` option.


<!-- The following details block can be found in benchmarks/tables_4_threads.md -->
<details><summary>Results: Single solution, 4 threads</summary>

Time per cube (in seconds, lower is better).

|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|
|:-----|:---|-------:|-------:|-------:|-------:|--------:|
|egg h11   |58.0 GiB|    0.00|    0.02|    0.06|    0.55|     0.03|
|H48 h11   |56.5 GiB|    0.03|    0.12|    0.48|    3.15|     4.15|
|egg h10   |29.0 GiB|    0.00|    0.02|    0.12|    1.02|     0.09|
|H48 h10   |28.3 GiB|    0.04|    0.17|    0.89|    6.14|     9.81|
|egg h9    |14.5 GiB|    0.01|    0.05|    0.23|        |         |
|H48 h9    |14.1 GiB|    0.07|    0.39|    1.71|   12.55|    18.81|
|egg h8    | 7.2 GiB|    0.02|    0.09|    0.43|        |         |
|H48 h8    | 7.1 GiB|    0.13|    0.90|    3.72|        |         |
|egg h7    | 3.6 GiB|    0.03|    0.19|    1.09|        |         |
|H48 h7    | 3.5 GiB|    0.17|    1.28|    6.13|        |         |
|egg h6    | 1.8 GiB|    0.05|    0.36|    2.01|        |         |
|H48 h6    | 1.8 GiB|    0.34|    2.48|   12.25|        |         |

Speed-up factor (higher is better).

|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|
|:-----|:---|-------:|-------:|-------:|-------:|--------:|
|egg h11   |58.0 GiB|    3.47|    3.78|    3.90|    3.88|     5.40|
|H48 h11   |56.5 GiB|    2.44|    3.40|    3.72|    3.79|     3.69|
|egg h10   |29.0 GiB|    3.68|    4.04|    3.78|    3.90|     2.72|
|H48 h10   |28.3 GiB|    2.80|    4.00|    3.72|    4.05|     3.89|
|egg h9    |14.5 GiB|    3.78|    3.95|    3.75|        |         |
|H48 h9    |14.1 GiB|    3.17|    3.70|    3.82|        |         |
|egg h8    | 7.2 GiB|    3.66|    3.97|    3.78|        |         |
|H48 h8    | 7.1 GiB|    3.52|    3.80|    3.83|        |         |
|egg h7    | 3.6 GiB|    3.78|    3.86|    3.68|        |         |
|H48 h7    | 3.5 GiB|    3.61|    3.82|    3.82|        |         |
|egg h6    | 1.8 GiB|    3.83|    3.92|    3.82|        |         |
|H48 h6    | 1.8 GiB|    3.74|    3.82|    3.82|        |         |

<img src="img/H48_4_threads_speedup_factor.png">
<img src="img/egg_4_threads_speedup_factor.png">

</details>

<!-- The following details block can be found in benchmarks/tables_16_threads.md -->
<details><summary>Results: Single solution, 16 threads</summary>

Time per cube (in seconds, lower is better).

|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|
|:-----|:---|-------:|-------:|-------:|-------:|--------:|
|egg h11   |58.0 GiB|    0.00|    0.01|    0.03|    0.26|     0.02|
|H48 h11   |56.5 GiB|    0.02|    0.05|    0.19|    1.13|     1.87|
|egg h10   |29.0 GiB|    0.00|    0.01|    0.06|    0.48|     0.05|
|H48 h10   |28.3 GiB|    0.02|    0.07|    0.33|    2.21|     4.17|
|egg h9    |14.5 GiB|    0.00|    0.02|    0.11|        |         |
|H48 h9    |14.1 GiB|    0.03|    0.14|    0.63|    4.39|     8.01|
|egg h8    | 7.2 GiB|    0.01|    0.04|    0.20|        |         |
|H48 h8    | 7.1 GiB|    0.06|    0.29|    1.36|        |         |
|egg h7    | 3.6 GiB|    0.01|    0.09|    0.52|        |         |
|H48 h7    | 3.5 GiB|    0.07|    0.40|    2.18|        |         |
|egg h6    | 1.8 GiB|    0.02|    0.16|    0.94|        |         |
|H48 h6    | 1.8 GiB|    0.13|    0.76|    4.33|        |         |

Speed-up factor (higher is better).

|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|
|:-----|:---|-------:|-------:|-------:|-------:|--------:|
|egg h11   |58.0 GiB|    6.70|    7.77|    8.08|    8.10|     9.07|
|H48 h11   |56.5 GiB|    3.72|    7.58|    9.52|   10.55|     8.19|
|egg h10   |29.0 GiB|    7.33|    8.53|    8.04|    8.27|     5.14|
|H48 h10   |28.3 GiB|    5.01|    9.25|   10.09|   11.22|     9.15|
|egg h9    |14.5 GiB|    7.65|    8.33|    7.96|        |         |
|H48 h9    |14.1 GiB|    6.48|   10.56|   10.37|        |         |
|egg h8    | 7.2 GiB|    7.78|    8.48|    8.04|        |         |
|H48 h8    | 7.1 GiB|    8.02|   11.69|   10.49|        |         |
|egg h7    | 3.6 GiB|    7.90|    8.22|    7.70|        |         |
|H48 h7    | 3.5 GiB|    8.78|   12.24|   10.73|        |         |
|egg h6    | 1.8 GiB|    8.16|    8.55|    8.21|        |         |
|H48 h6    | 1.8 GiB|    9.75|   12.48|   10.80|        |         |

<img src="img/H48_16_threads_speedup_factor.png">
<img src="img/egg_16_threads_speedup_factor.png">

</details>

We can see that both egg-solver and H48 scale pretty well with 4 threads,
getting close to the 4x theoretical maximum speedup in slower cases
(small table or long solutions). egg-solver managed to beat the 4x
speedup for the superflip, likely due to single-scramble variance, i.e.
the thread that found the solution stopped earlier.

The 16 threads benchmark shows that, although the virtual threads help
push H48 beyond the 8x theoretical speedup that would be provided by the
8 cores, it is nowhere near a 16x speedup. Moreover, egg-solver does not
seem to take advantage of the CPU's hyperthreading, likely because its
own custom micro-threading is based on the same principle and it saturates
any possible speedup that hyperthreading could provide.

### All solutions

Finally, we ran a test on finding *all* optimal solutions which, as
far as I know, is a use case only supported by H48 and egg-solver.
For convenience, this test is only run on 16 threads.

<!-- The following details block can be found in benchmarks/tables_all_solutions.md -->
<details><summary>Results: All solutions, 16 threads</summary>

Time per cube (in seconds, lower is better).

|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|
|:-----|:---|-------:|-------:|-------:|-------:|--------:|
|egg h11   |58.0 GiB|    0.00|    0.04|    0.41|    3.91|     0.30|
|H48 h11   |56.5 GiB|    0.03|    0.22|    1.89|   16.01|    17.02|
|egg h10   |29.0 GiB|    0.01|    0.07|    0.74|    7.08|     0.60|
|H48 h10   |28.3 GiB|    0.05|    0.38|    3.60|   30.97|    36.41|
|egg h9    |14.5 GiB|    0.01|    0.13|    1.43|        |         |
|H48 h9    |14.1 GiB|    0.07|    0.71|    7.14|        |         |
|egg h8    | 7.2 GiB|    0.02|    0.25|    2.78|        |         |
|H48 h8    | 7.1 GiB|    0.14|    1.52|   15.20|        |         |
|egg h7    | 3.6 GiB|    0.04|    0.49|    5.83|        |         |
|H48 h7    | 3.5 GiB|    0.21|    2.33|   26.16|        |         |
|egg h6    | 1.8 GiB|    0.07|    0.91|   10.96|        |         |
|H48 h6    | 1.8 GiB|    0.39|    4.60|   52.07|        |         |

Time per cube adjusted for table size (in seconds \* GiB, lower is better).

|Solver|Size|17 moves|18 moves|19 moves|20 moves|Superflip|
|:-----|:---|-------:|-------:|-------:|-------:|--------:|
|egg h11   |58.0 GiB|    0.20|    2.21|   23.79|  226.71|    17.30|
|H48 h11   |56.5 GiB|    1.81|   12.50|  107.05|  904.39|   961.58|
|egg h10   |29.0 GiB|    0.17|    1.94|   21.32|  205.40|    17.50|
|H48 h10   |28.3 GiB|    1.29|   10.85|  101.62|  874.93|  1028.73|
|egg h9    |14.5 GiB|    0.15|    1.83|   20.75|        |         |
|H48 h9    |14.1 GiB|    1.04|   10.03|  100.84|        |         |
|egg h8    | 7.2 GiB|    0.15|    1.78|   20.16|        |         |
|H48 h8    | 7.1 GiB|    1.01|   10.77|  107.38|        |         |
|egg h7    | 3.6 GiB|    0.14|    1.78|   21.14|        |         |
|H48 h7    | 3.5 GiB|    0.73|    8.25|   92.42|        |         |
|egg h6    | 1.8 GiB|    0.13|    1.66|   19.86|        |         |
|H48 h6    | 1.8 GiB|    0.69|    8.13|   92.04|        |         |

<img src="img/17movesallsolutions16threads.png">
<img src="img/18movesallsolutions16threads.png">
<img src="img/19movesallsolutions16threads.png">
<img src="img/20movesallsolutions16threads.png">

</details>

## Other notes

* To repeat the benchmarks for H48, use `./benchmarks/run-h48-benchmarks.sh`.
  Similar scripts for vcube and egg-solver can be found in the `benchmarks`
  folder.
* All the measurements above exclude the time needed to load the pruning
  tables into memory, which can be quite significant for large tables.
* The measurements also excluded the one-off computation of the pruning
  tables which, for reasons related to the cube coordinates used, is
  significantly slower for H48 compared to vcube.
* H48's and vcube's approach to multithreading are extremely different:
  H48 parallelize the search for each cube individually, vcube solves
  multiple cubes in parallel by dedicating a single thread to each of
  them. Both apporaches have pros and cons: vcube's approch has less
  overhead in coordination between the threads, but often some threads
  may be left without work when there are no more cubes left to solve.
  egg-solver supports both modes via the `-c` option.
* Per-cube parallelization means that H48 will always be faster than
  vcube when solving a single cube.
* vcube only supports x86 processors (Intel, AMD), while H48 runs on any
  architecture, including e.g. ARM (Macbook M series, android phones)
  and can be compiled to WebAssembly as well.
* For H48, both GCC and Clang have been tried, with the same options;
  the resulting executable was about 10% faster with GCC compared to Clang.
  vcube only supports compiling with Clang.

Generated with cgit - Back to sebastiano.tronto.net