Rev 108 | Go to most recent revision | Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 33 | pmbaty | 1 | #include "chess.h" |
| 2 | #include "data.h" |
||
| 3 | /* last modified 02/26/14 */ |
||
| 4 | /* |
||
| 5 | ******************************************************************************* |
||
| 6 | * * |
||
| 7 | * Bench() runs a simple six-position benchmark to gauge Crafty's * |
||
| 8 | * performance. The test positons are hard-coded, and the benchmark is * |
||
| 9 | * calculated much like it would with an external "test" file. The test * |
||
| 10 | * is a mix of opening, middlegame, and endgame positions, with both * |
||
| 11 | * tactical and positional aspects. (For those interested, the positions * |
||
| 12 | * chosen are Bratko-Kopec 2, 4, 8, 12, 22 and 23.) This test is a speed * |
||
| 13 | * measure only; the actual solutions to the positions are ignored. * |
||
| 14 | * * |
||
| 15 | ******************************************************************************* |
||
| 16 | */ |
||
| 17 | void Bench(int increase) { |
||
| 18 | uint64_t nodes = 0; |
||
| 19 | int old_do, old_st, old_sd, total_time_used, pos; |
||
| 20 | FILE *old_books, *old_book; |
||
| 21 | TREE *const tree = block[0]; |
||
| 22 | char fen[6][80] = { |
||
| 23 | {"3r1k2/4npp1/1ppr3p/p6P/P2PPPP1/1NR5/5K2/2R5 w - - 0 1"}, |
||
| 24 | {"rnbqkb1r/p3pppp/1p6/2ppP3/3N4/2P5/PPP1QPPP/R1B1KB1R w KQkq - 0 1"}, |
||
| 25 | {"4b3/p3kp2/6p1/3pP2p/2pP1P2/4K1P1/P3N2P/8 w - - 0 1"}, |
||
| 26 | {"r3r1k1/ppqb1ppp/8/4p1NQ/8/2P5/PP3PPP/R3R1K1 b - - 0 1"}, |
||
| 27 | {"2r2rk1/1bqnbpp1/1p1ppn1p/pP6/N1P1P3/P2B1N1P/1B2QPP1/R2R2K1 b - - 0 1"}, |
||
| 28 | {"r1bqk2r/pp2bppp/2p5/3pP3/P2Q1P2/2N1B3/1PP3PP/R4RK1 b kq - 0 1"} |
||
| 29 | }; |
||
| 30 | int fen_depth[6] = { 21, 19, 25, 19, 19, 18 }; |
||
| 31 | |||
| 32 | /* |
||
| 33 | ************************************************************ |
||
| 34 | * * |
||
| 35 | * Initialize. * |
||
| 36 | * * |
||
| 37 | ************************************************************ |
||
| 38 | */ |
||
| 39 | total_time_used = 0; |
||
| 40 | old_st = search_time_limit; |
||
| 41 | old_sd = search_depth; |
||
| 42 | old_do = display_options; |
||
| 43 | search_time_limit = 90000; |
||
| 44 | display_options = 1; |
||
| 45 | old_book = book_file; |
||
| 46 | book_file = 0; |
||
| 47 | old_books = books_file; |
||
| 48 | books_file = 0; |
||
| 49 | if (increase) |
||
| 50 | Print(4095, "Running benchmark %d. . .\n", increase); |
||
| 51 | else |
||
| 52 | Print(4095, "Running benchmark. . .\n"); |
||
| 53 | printf("."); |
||
| 54 | fflush(stdout); |
||
| 55 | /* |
||
| 56 | ************************************************************ |
||
| 57 | * * |
||
| 58 | * Now we loop through the six positions. We use the * |
||
| 59 | * ReadParse() procedure to break the FEN into tokens and * |
||
| 60 | * then call SetBoard() to set up the positions. Then a * |
||
| 61 | * call to Iterate() and we are done. * |
||
| 62 | * * |
||
| 63 | ************************************************************ |
||
| 64 | */ |
||
| 65 | for (pos = 0; pos < 6; pos++) { |
||
| 66 | strcpy(buffer, fen[pos]); |
||
| 67 | nargs = ReadParse(buffer, args, " \t;="); |
||
| 68 | SetBoard(tree, nargs, args, 0); |
||
| 69 | search_depth = fen_depth[pos] + increase; |
||
| 70 | InitializeHashTables(); |
||
| 71 | last_pv.pathd = 0; |
||
| 72 | thinking = 1; |
||
| 73 | tree->status[1] = tree->status[0]; |
||
| 74 | (void) Iterate(game_wtm, think, 0); |
||
| 75 | thinking = 0; |
||
| 76 | nodes += tree->nodes_searched; |
||
| 77 | total_time_used += (program_end_time - program_start_time); |
||
| 78 | printf("."); |
||
| 79 | fflush(stdout); |
||
| 80 | } |
||
| 81 | /* |
||
| 82 | ************************************************************ |
||
| 83 | * * |
||
| 84 | * Benchmark done. Now dump the results. * |
||
| 85 | * * |
||
| 86 | ************************************************************ |
||
| 87 | */ |
||
| 88 | printf("\n"); |
||
| 89 | Print(4095, "Total nodes: %" PRIu64 "\n", nodes); |
||
| 90 | Print(4095, "Raw nodes per second: %d\n", |
||
| 91 | (int) ((double) nodes / ((double) total_time_used / (double) 100.0))); |
||
| 92 | Print(4095, "Total elapsed time: %.2f\n", |
||
| 93 | ((double) total_time_used / (double) 100.0)); |
||
| 94 | input_stream = stdin; |
||
| 95 | early_exit = 99; |
||
| 96 | display_options = old_do; |
||
| 97 | search_time_limit = old_st; |
||
| 98 | search_depth = old_sd; |
||
| 99 | books_file = old_books; |
||
| 100 | book_file = old_book; |
||
| 101 | NewGame(0); |
||
| 102 | } |