-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBenchmark.hs
86 lines (75 loc) · 2.03 KB
/
Benchmark.hs
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
import Control.DeepSeq
import Criterion.Main
import AI
import Analysis
import Board.Naive
import Board.UVectorBased
import Board.UArrayBased
import Board.Vector16
import Game
import Types
instance NFData Move where
rnf (Move x y) = rnf x `seq` rnf y
losing :: Depth -> [Move]
losing = losingFirstMoves Negascout My
best :: Depth -> (PV, Int)
best = bestMove Negascout My
testMoves :: [Move]
testMoves =
[ Move (6,1) (6,7)
, Move (5,8) (5,3)
, Move (3,1) (3,7)
, Move (4,8) (6,6)
, Move (1,1) (1,2)
, Move (3,8) (8,3)
, Move (2,1) (2,7)
, Move (1,8) (1,3)
, Move (7,1) (7,7)
, Move (8,8) (8,4)
, Move (5,1) (4,2)
, Move (2,8) (1,7)
, Move (3,7) (3,8)
]
{-
Number of entries of methods of Board class during profiling:
function entries inherited time, %
-----------------------------------------
board0 1 0.0%
updateBoard 2160288 5.7%
fieldIsEmpty 16426738 1.4%
fieldColor 2161130 2.5%
pieceCoord 2251130 34.7%
pieceCoords ? ?
-}
boardBench :: Board b => Position b -> Int
boardBench r0 =
let -- 13 update boards
b = pBoard $ doMoves testMoves r0
-- 64 field is empty
empties = length $ filter (fieldIsEmpty b) coords
-- 16 field color
reds = length [ () | x <- [1..2], y <- [1..8], let col = fieldColor b (x,y), col == Red]
-- 16 piece coords
x = sum [ x + y | p <- [Black, White], c <- colors, let (x,y) = pieceCoord b p c ]
in empties + reds + x
main :: IO ()
main = defaultMain
[ bgroup "losing"
[ bench "d5" $ nf losing 5
, bench "d7" $ nf losing 7
, bench "d9" $ nf losing 9
, bench "d11" $ nf losing 11
]
, bgroup "best"
[ bench "d5" $ nf best 5
, bench "d7" $ nf best 7
]
, bgroup "board"
[ bcompare
[ bench "normal" $ nf boardBench (position0 :: Position NaiveBoard)
, bench "uarray" $ nf boardBench (position0 :: Position ABoard)
, bench "uvector" $ nf boardBench (position0 :: Position VBoard)
, bench "uvector16" $ nf boardBench (position0 :: Position VBoard16)
]
]
]