diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-17 09:26:53 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-12-17 09:26:53 +0100 |
| commit | 36f37564cd566e91771cd1f92ac3886917c769d1 (patch) | |
| tree | 037b21f46dafb4edce8aeef25fc3d6e1d607df12 /benchmarks/plot-benchmarks.py | |
| parent | c6ab40b1602443938e431b996b28fb3d888365bb (diff) | |
| download | nissy-core-36f37564cd566e91771cd1f92ac3886917c769d1.tar.gz nissy-core-36f37564cd566e91771cd1f92ac3886917c769d1.zip | |
Update benchmarks
Diffstat (limited to '')
| -rw-r--r-- | benchmarks/plot-benchmarks.py | 161 |
1 files changed, 161 insertions, 0 deletions
diff --git a/benchmarks/plot-benchmarks.py b/benchmarks/plot-benchmarks.py new file mode 100644 index 0000000..b42c4ba --- /dev/null +++ b/benchmarks/plot-benchmarks.py | |||
| @@ -0,0 +1,161 @@ | |||
| 1 | import matplotlib.pyplot as plt | ||
| 2 | import results_h48 | ||
| 3 | import results_vcube | ||
| 4 | |||
| 5 | # Table sizes in bytes | ||
| 6 | |||
| 7 | sizes_h48 = { | ||
| 8 | 6: 1897951528, | ||
| 9 | 7: 3793842344, | ||
| 10 | 8: 7585624040, | ||
| 11 | 9: 15169187432, | ||
| 12 | 10: 30336314216, | ||
| 13 | 11: 60670567784, | ||
| 14 | } | ||
| 15 | |||
| 16 | sizes_vcube = { | ||
| 17 | 112: 2603089920, | ||
| 18 | 208: 7809269760, | ||
| 19 | 308: 22777036800, | ||
| 20 | 404: 34165555200, | ||
| 21 | 212: 62474158080, | ||
| 22 | } | ||
| 23 | |||
| 24 | # Printing tables in markdown format | ||
| 25 | |||
| 26 | def print_row(solver_name, solver_size, dict, mul_by_size, superflip_star): | ||
| 27 | if dict is None: | ||
| 28 | return | ||
| 29 | solver_gib = solver_size / (2**30) | ||
| 30 | m = solver_gib if mul_by_size else 1 | ||
| 31 | s = " (a) " if superflip_star else " " | ||
| 32 | cols = [f"{solver_name: <10}", f"{solver_gib:>4.1f} Gib"] + [ | ||
| 33 | f"{dict[key]*m/25:>8.2f}" if key in dict else " " | ||
| 34 | for key in [17, 18, 19, 20] | ||
| 35 | ] + [ | ||
| 36 | f"{dict["superflip"]*m:>9.2f}" if "superflip" in dict else s | ||
| 37 | ] | ||
| 38 | sep = "|" | ||
| 39 | print(sep + sep.join(cols) + sep) | ||
| 40 | |||
| 41 | def print_table(h48, vcube, ms, st): | ||
| 42 | vcube = vcube or {} | ||
| 43 | print("| Solver | Size |17 moves|18 moves|19 moves|20 moves|Superflip|") | ||
| 44 | print("|:---------|:-------|-------:|-------:|-------:|-------:|--------:|") | ||
| 45 | print_row("vcube 212", sizes_vcube[212], vcube.get(212), ms, not st) | ||
| 46 | print_row("H48 h11", sizes_h48[11], h48[11], ms, False) | ||
| 47 | print_row("vcube 404", sizes_vcube[404], vcube.get(404), ms, not st) | ||
| 48 | print_row("H48 h10", sizes_h48[10], h48[10], ms, False) | ||
| 49 | print_row("vcube 308", sizes_vcube[308], vcube.get(308), ms, not st) | ||
| 50 | print_row("H48 h9", sizes_h48[9], h48[9], ms, False) | ||
| 51 | print_row("vcube 208", sizes_vcube[208], vcube.get(208), ms, not st) | ||
| 52 | print_row("H48 h8", sizes_h48[8], h48[8], ms, False) | ||
| 53 | print_row("H48 h7", sizes_h48[7], h48[7], ms, False) | ||
| 54 | print_row("vcube 112", sizes_vcube[112], vcube.get(112), ms, not st) | ||
| 55 | print_row("H48 h6", sizes_h48[6], h48[6], ms, False) | ||
| 56 | |||
| 57 | print("<details><summary>Single solution, single thread</summary>") | ||
| 58 | print() | ||
| 59 | print("Time per cube (in seconds, lower is better).") | ||
| 60 | print() | ||
| 61 | print_table(results_h48.h48_single_thread, results_vcube.vcube_single_thread, False, True) | ||
| 62 | print() | ||
| 63 | print("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).") | ||
| 64 | print() | ||
| 65 | print_table(results_h48.h48_single_thread, results_vcube.vcube_single_thread, True, True) | ||
| 66 | print() | ||
| 67 | print( | ||
| 68 | '<img src="img/17moves1thread.png">\n' | ||
| 69 | '<img src="img/18moves1thread.png">\n' | ||
| 70 | '<img src="img/19moves1thread.png">\n' | ||
| 71 | '<img src="img/20moves1thread.png">\n' | ||
| 72 | ) | ||
| 73 | print("</details>") | ||
| 74 | |||
| 75 | print("<details><summary>Single solution, 4 threads</summary>") | ||
| 76 | print() | ||
| 77 | print("Time per cube (in seconds, lower is better).") | ||
| 78 | print() | ||
| 79 | print_table(results_h48.h48_4_threads, results_vcube.vcube_4_threads, False, False) | ||
| 80 | print() | ||
| 81 | print("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).") | ||
| 82 | print() | ||
| 83 | print_table(results_h48.h48_4_threads, results_vcube.vcube_4_threads, True, False) | ||
| 84 | print() | ||
| 85 | print( | ||
| 86 | '<img src="img/17moves4threads.png">\n' | ||
| 87 | '<img src="img/18moves4threads.png">\n' | ||
| 88 | '<img src="img/19moves4threads.png">\n' | ||
| 89 | '<img src="img/20moves4threads.png">\n' | ||
| 90 | ) | ||
| 91 | print() | ||
| 92 | print("(a) vcube cannot parallelize on a single scramble, the results for the") | ||
| 93 | print("superflip are going to be the same as in the single thread case.") | ||
| 94 | print("</details>") | ||
| 95 | |||
| 96 | print("<details><summary>Single solution, 16 threads</summary>") | ||
| 97 | print() | ||
| 98 | print("Time per cube (in seconds, lower is better).") | ||
| 99 | print() | ||
| 100 | print_table(results_h48.h48_16_threads, results_vcube.vcube_16_threads, False, False) | ||
| 101 | print() | ||
| 102 | print("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).") | ||
| 103 | print() | ||
| 104 | print_table(results_h48.h48_16_threads, results_vcube.vcube_16_threads, True, False) | ||
| 105 | print() | ||
| 106 | print( | ||
| 107 | '<img src="img/17moves16threads.png">\n' | ||
| 108 | '<img src="img/18moves16threads.png">\n' | ||
| 109 | '<img src="img/19moves16threads.png">\n' | ||
| 110 | '<img src="img/20moves16threads.png">\n' | ||
| 111 | ) | ||
| 112 | print() | ||
| 113 | print("(a) vcube cannot parallelize on a single scramble, the results for the") | ||
| 114 | print("superflip are going to be the same as in the single thread case.") | ||
| 115 | print("</details>") | ||
| 116 | |||
| 117 | print("<details><summary>All solutions, 16 threads</summary>") | ||
| 118 | print() | ||
| 119 | print("*Note: vcube does not have an option for finding multiple solutions.*") | ||
| 120 | print() | ||
| 121 | print("Time per cube (in seconds, lower is better).") | ||
| 122 | print() | ||
| 123 | print_table(results_h48.h48_all_solutions, None, False, False) | ||
| 124 | print() | ||
| 125 | print("Time per cube adjusted for table size (in seconds \\* GiB, lower is better).") | ||
| 126 | print() | ||
| 127 | print_table(results_h48.h48_all_solutions, None, True, False) | ||
| 128 | print() | ||
| 129 | print("</details>") | ||
| 130 | |||
| 131 | # Plotting | ||
| 132 | |||
| 133 | def plot(title, hd, vd, key): | ||
| 134 | d = 1 if key == "superflip" else 25 | ||
| 135 | h48x = [sizes_h48[m]/(2**30) for m in hd.keys() if key in hd[m]] | ||
| 136 | vcubex = [sizes_vcube[m]/(2**30) for m in vd.keys() if key in vd[m]] | ||
| 137 | h48y = [d[key] for _, d in hd.items() if key in d] | ||
| 138 | vcubey = [d[key] for _, d in vd.items() if key in d] | ||
| 139 | |||
| 140 | plt.clf() | ||
| 141 | plt.title(title) | ||
| 142 | plt.xlabel("Table size (GiB)") | ||
| 143 | plt.ylabel("Time to solve (s / cube)") | ||
| 144 | plt.plot(h48x, h48y, "o--", label = "H48") | ||
| 145 | plt.plot(vcubex, vcubey, "o--", label = "vcube") | ||
| 146 | plt.legend(loc = "right") | ||
| 147 | filename = title.replace(" ", "").replace(",", "") + ".png" | ||
| 148 | plt.savefig("benchmarks/img/" + filename, dpi=300) | ||
| 149 | #plt.show() | ||
| 150 | |||
| 151 | rh, rv = results_h48.h48_single_thread, results_vcube.vcube_single_thread | ||
| 152 | for m in [17, 18, 19, 20]: | ||
| 153 | plot(f"{m} moves 1 thread", rh, rv, m) | ||
| 154 | |||
| 155 | rh, rv = results_h48.h48_4_threads, results_vcube.vcube_4_threads | ||
| 156 | for m in [17, 18, 19, 20]: | ||
| 157 | plot(f"{m} moves 4 threads", rh, rv, m) | ||
| 158 | |||
| 159 | rh, rv = results_h48.h48_16_threads, results_vcube.vcube_16_threads | ||
| 160 | for m in [17, 18, 19, 20]: | ||
| 161 | plot(f"{m} moves 16 threads", rh, rv, m) | ||
