From 0c202900fa37114ab75db1c839aede73b29233c6 Mon Sep 17 00:00:00 2001 From: Tait Hoyem <44244401+TTWNO@users.noreply.github.com> Date: Mon, 29 Apr 2019 22:22:20 +0000 Subject: [PATCH] Add various compile options, and remove some whitespace --- tests/Makefile | 4 ++++ tests/speed.cpp | 28 +++++++++++++++++++++++++++- tests/valid_moves.h | 1 - 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/tests/Makefile b/tests/Makefile index 2a8f2f5..6b5afa3 100755 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,6 +1,7 @@ defualt: all.out bitwise: bitwise.out release: all_optimized.out +speed_tests: speed_tests.out clean: rm all.out @@ -32,3 +33,6 @@ bitwise_optimized.out: catch_main_optimized.o all_optimized.out: catch_main_optimized.o custom_printing_optimized.o g++ -std=c++11 -O2 -Wall -I../src/ -o all_optimized.out ../src/functions.cpp catch_main_optimized.o custom_printing_optimized.o test_functions.cpp main.cpp + +speed_tests.out: + g++ -O2 -Wall -I../src/ -o speed_tests.out ../src/functions.cpp speed.cpp diff --git a/tests/speed.cpp b/tests/speed.cpp index 704f175..e2692c4 100644 --- a/tests/speed.cpp +++ b/tests/speed.cpp @@ -1,3 +1,4 @@ +#include "valid_moves.h" #include #include #include @@ -9,9 +10,21 @@ using namespace std; using namespace std::chrono; +#define TEST_FUNCTION(pre_func, function_with_params, number_of_times_to_run, test_number){\ + high_resolution_clock::time_point ts_(test_number) = high_resolution_clock::now();\ + for (int i = 0; i < (number_of_times_to_run); ++i){\ + (pre_func);\ + (functions_with_params);\ + }\ + high_resolution_clock::time_print te_(test_number) = high_resolution_clock::now();\ + auto duration = duration_cast(te_(test_number) - ts_(test_number)).count();\ + cout << "Function (functions_with_params) ran (number_of_times_to_run) times in " << duration_(test_number) << " micro seconds" << endl; + + // TODO make complete, add complex scenarios. // Test every function on their edge cases. int main(){ + // Get all moves high_resolution_clock::time_point t1 = high_resolution_clock::now(); for (int i = 0; i < 10000000; i++){ vector moves = {}; @@ -19,6 +32,19 @@ int main(){ } high_resolution_clock::time_point t2 = high_resolution_clock::now(); auto duration = duration_cast( t2 - t1 ).count(); - cout << "10,000,000 iterations of get_all_moves took " << duration << " micro seconds" << endl; + + // to_notation (Rook) + high_resolution_clock::time_point t3 = high_resolution_clock::now(); + std::vector checkmate_rook_moves; + get_all_moves(CHECKMATE_ROOK_POS, CHECKMATE_ROOK_BOARD, checkmate_rook_moves); + for (int i = 0; i < 1000000; i++){ + for (int mv : checkmate_rook_moves){ + string notation = to_notation(mv, CHECKMATE_ROOK_BOARD); + } + } + high_resolution_clock::time_point t4 = high_resolution_clock::now(); + auto duration2 = duration_cast( t4 - t3 ).count(); + + cout << "~15,000,000 iterations of to_notation took " << duration2 << " micro seconds" << endl; } diff --git a/tests/valid_moves.h b/tests/valid_moves.h index a15a4b3..38f2d57 100644 --- a/tests/valid_moves.h +++ b/tests/valid_moves.h @@ -2,7 +2,6 @@ #include #include - /// This is for possible moves on a default board const std::vector DEFAULT_B_A_PAWN_POSSIBLE_MOVES = { A6, A5