The Requests is quite a good Python library. It simplifies using the ugly and terrible standard Python HTTP libraries. The more I think about the interfaces, the more I think that there is lots of places to improve including the Requests library.
In a couple of previousposts 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.
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 I couldn’t stop thinking about. The huge memory overhead and the huge execution time.
The process used 50MB of memory 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).
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, you can find it there.
Some time ago there was a discussion on IRC, which looked like this:
- You should not use the map() function
in Python but the only list comprehension.
- Why?
- Because it is more Pythonic.
- Why?
- Because all people use the list comprehension.
Other arguments were not convincing as well. I have written about the map and the list comprehension in Advanced Python Constructs.
Arguments like “because I say it” or “all people do it like this” (evidence please) are just stupid, not convincing, and simply false (I use map so that’s not true that all people don't use it). So I have decided to make some benchmarks for the memory/time characteristics for list comprehensions and maps.