einfaches timen vom brute-force
This commit is contained in:
@@ -15,16 +15,8 @@ class BruteForceSolver:
|
|||||||
self.game.set_direction(x, y, Direction.UP)
|
self.game.set_direction(x, y, Direction.UP)
|
||||||
|
|
||||||
def solve(self) -> Generator[None]:
|
def solve(self) -> Generator[None]:
|
||||||
attempts = 0
|
|
||||||
required = 4 ** (self.game.width * self.game.height)
|
|
||||||
while not self.game.solved():
|
while not self.game.solved():
|
||||||
yield
|
yield
|
||||||
attempts += 1
|
|
||||||
|
|
||||||
print(
|
|
||||||
f"{attempts:0>{len(str(required))}}/{required} ({attempts / required * 100}%) ",
|
|
||||||
end="\r",
|
|
||||||
)
|
|
||||||
self.game.turn_cw(0, 0)
|
self.game.turn_cw(0, 0)
|
||||||
for prev, curr in pairwise(
|
for prev, curr in pairwise(
|
||||||
chain(
|
chain(
|
||||||
|
|||||||
24
src/algorithms/profile.py
Normal file
24
src/algorithms/profile.py
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import time
|
||||||
|
from multiprocessing import Pool
|
||||||
|
|
||||||
|
from src.algorithms.bruteforce import BruteForceSolver
|
||||||
|
from src.net import NetGame
|
||||||
|
|
||||||
|
|
||||||
|
def test_run() -> float:
|
||||||
|
game = NetGame(3, 3)
|
||||||
|
solver = BruteForceSolver(game)
|
||||||
|
a = time.perf_counter()
|
||||||
|
for _ in solver.solve():
|
||||||
|
pass
|
||||||
|
b = time.perf_counter()
|
||||||
|
return b - a
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
total = 0
|
||||||
|
with Pool() as p:
|
||||||
|
processes = [p.apply_async(test_run) for _ in range(100)]
|
||||||
|
for proc in processes:
|
||||||
|
total += proc.get()
|
||||||
|
print(total)
|
||||||
Reference in New Issue
Block a user