GeneticAlgorithmsWithPython icon indicating copy to clipboard operation
GeneticAlgorithmsWithPython copied to clipboard

Chapter 3 code runs slow for me

Open marc9323 opened this issue 5 years ago • 2 comments

Hi, I'm really enjoying your book! I've learned a lot in just the first three chapters.

I've run into an issue however running the chapter 3 code from the book. ( sorted number list ) The benchmark test sorts 40 numbers. I'm running exactly the same code (copied from github) and it takes 63 seconds to complete. Something has to be wrong here. I'm on a Dell Laptop (Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz, 1992 Mhz, 4 Core(s), 8 Logical Processor(s)).

I'm running the same code that in the book it says on page 44: "1-2 seconds to run on average". I know processors vary but this seems extreme.

Is this normal behavior? I'm new to python and benchmarking so would appreciate any clarification. Thanks, Marc

marc9323 avatar Oct 15 '19 00:10 marc9323

Marc,

The benchmark test doesn't take 1-2 seconds to run, it runs something 100 times and prints the average run time and standard deviation. In this case it times running a sort round that takes 1-2 seconds to run on average. Using Python 3.5, my box sorts 40 numbers in 1.27 seconds on average. That means when I run the benchmark test it takes about 127 seconds to run. Combined, your CPU and Python version run the same test twice as fast. That's why how many numbers you choose to sort is processor dependent. The benchmark test is useful for tracking whether a change to the engine has negatively impacted the speed of the engine. I also find it useful for detecting performance problems in the algorithm code.

Clinton

handcraftsman avatar Oct 15 '19 12:10 handcraftsman

Hi Clinton,

Thank you for your reply! You explanation was very helpful.

And thanks again for great book! Python is an amazing language and it's great to learn from such practical applications as you present.

Regards, Marc

On Tue, Oct 15, 2019 at 7:01 AM Cℓinton Sheppard [email protected] wrote:

Marc,

The benchmark test doesn't take 1-2 seconds to run, it runs something 100 times and prints the average run time and standard deviation. In this case it times running a sort round that takes 1-2 seconds to run on average. Using Python 3.5, my box sorts 40 numbers in 1.27 seconds on average. That means when I run the benchmark test it takes about 127 seconds to run. Combined, your CPU and Python version run the same test twice as fast. That's why how many numbers you choose to sort is processor dependent. The benchmark test is useful for tracking whether a change to the engine has negatively impacted the speed of the engine. I also find it useful for detecting performance problems in the algorithm code.

Clinton

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/handcraftsman/GeneticAlgorithmsWithPython/issues/7?email_source=notifications&email_token=AHT6HXJVRZW5OUTUFYLS7YTQOWWINA5CNFSM4JAVWPX2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBIPPRQ#issuecomment-542177222, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHT6HXOWU4G7NXXWUM4SL33QOWWINANCNFSM4JAVWPXQ .

marc9323 avatar Oct 15 '19 15:10 marc9323