Jan-05-2023, 03:34 AM
I wrote a quick-n-dirty test by hand just to see how quick it would be. A little optimization will make it much faster. I wrote it in C, so the players list is dynamically allocated array of pointers. An array of player structs would be faster as would a C++ vector. I am using a new compiler and trying to learn how to wirte C/C++ using VSCode instead of Visual Studio or the gnu compiler and command line tools. Not sure what compiler optimization settings are, but I doubt that my executable is "highly optimized".
I modified my code to use structs and arrays of structs instead of pointers. This allows certain optimizations by the compiler. When I run my new, very ugly but optimized code it takes 2 minutes to find the best team that can be made from 400 players. I ran my timing test multiple times because the player list will affect timing. The fastest time was 1 minute 42 seconds. The worst was 3 minutes 17 seconds.
A really fun comparison is looking at the time for 60 teams. You posted that your numpy code for solving the problem ran for 3366 seconds to come up with a solution. My C program solves it in 0.016 seconds. 210,375 times faster. The C program is also 724 times faster than my solution that used combinations and 47 times faster than my Python program that uses loops.
I modified my code to use structs and arrays of structs instead of pointers. This allows certain optimizations by the compiler. When I run my new, very ugly but optimized code it takes 2 minutes to find the best team that can be made from 400 players. I ran my timing test multiple times because the player list will affect timing. The fastest time was 1 minute 42 seconds. The worst was 3 minutes 17 seconds.
A really fun comparison is looking at the time for 60 teams. You posted that your numpy code for solving the problem ran for 3366 seconds to come up with a solution. My C program solves it in 0.016 seconds. 210,375 times faster. The C program is also 724 times faster than my solution that used combinations and 47 times faster than my Python program that uses loops.