In a couple of previous posts I was considering which is better in Python: map or list comprehension. The final idea was that none of them is as fast as a C++ program, even using exactly the same algorithm.
What about changing an algorithm a little bit?
In the previous blog post I have presented results of benchmarking list comprehensions, and maps in Python.
The results looked fine, however there was one thing that I couldn’t stop thinking about. The memory overhead, and the huge execution time.
The process wanted to use the 50MB from the beginning. Then it had just to iterate through a list of integers (which are small). The number of integers is also small (only 1M).
Then it had to make 1M divisions to find the even numbers, and square it (making 0.5M multiplications, and 0.5M additions).
Why did it take 1.5 minute?
In the previous blog post I have presented results of benchmarking list comprehensions and maps. In this one I will run similar tests, but I will filter the list to use only the even numbers.
I will not repeat the test description from the previous article.