mynameisfiber / high_performance_python_2e Goto Github PK
View Code? Open in Web Editor NEWCode for the book "High Performance Python 2e" by Micha Gorelick and Ian Ozsvald with OReilly
License: Other
Code for the book "High Performance Python 2e" by Micha Gorelick and Ian Ozsvald with OReilly
License: Other
Hi, I'm not sure if the code will be added, but in
Example 3-7 Memory and time consequences of appends versus list comprehensions
>>> %memit [i*i for i in range(100_000)]
peak memory: 70.50 MiB, increment: 3.02 MiB
>>> %%memit l = []
... for i in range(100_000):
... l.append(i * 2)
...
peak memory: 67.47 MiB, increment: 8.17 MiB
it is said "In Example 3-7, we can see that even for 100,000 elements, we use 2.7ร the memory by building the list with appends versus a list comprehension."
I can not reproduce this with Python 3.8.5.
Neither in a Notebook:
[1]
%load_ext memory_profiler
%load_ext line_profiler
[2]
%memit [i*i for i in range(100_000)]
peak memory: 52.02 MiB, increment: 3.74 MiB
[3]
%%memit
l = []
for i in range(100_000):
l.append(i * 2)
peak memory: 52.66 MiB, increment: 2.95 MiB
nor outside a notebook:
Filename: list_append.py
Line # Mem usage Increment Line Contents
================================================
8 38.5 MiB 38.5 MiB @profile
9 def append_to_list() -> List[int]:
10 """Append to list example."""
11 38.5 MiB 0.0 MiB result = []
12 42.4 MiB 0.0 MiB for i in range(100_000):
13 42.4 MiB 0.3 MiB result.append(i * 2)
14 42.4 MiB 0.0 MiB return result
Filename: list_append.py
Line # Mem usage Increment Line Contents
================================================
17 39.4 MiB 39.4 MiB @profile
18 def comp() -> List[int]:
19 """Comprehend example."""
20 42.2 MiB 0.2 MiB return [i * i for i in range(100_000)]
Same is true for larger lists:
[2]
%memit [i*i for i in range(100_000_000)]
peak memory: 3849.21 MiB, increment: 3801.23 MiB
[3]
%%memit
l = []
for i in range(100_000_000):
l.append(i * 2)
peak memory: 3912.98 MiB, increment: 3863.53 MiB
Thanks for the excellent book! I'm enjoying working my way through it.
In Example 6.5 on page 117, I think the following sentence:
This statement takes such a long time per hit because
grid_shape
must be retrieved from the local namespace
should read:
This statement takes such a long time per hit because
grid_shape
must be retrieved from the global namespace
Hi. I have an issue on where I can find and download the file described in
.I would like to run the code but I cannot quite find this file to download. Plus in the book there seems no clear instruction on how I can find and download it. Could you help me on this.
Thanks.
Hi there. Thanks for writing the book. This is just a friendly question of whether or not the code for 2e will be available at some moment. I noticed this repo contains many empty directories etc and appears to be scaffolding
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.