Source code online books for professionals by professionals


Appendix A Pedal to the Metal: Accelerating



Download 4,67 Mb.
Pdf ko'rish
bet212/266
Sana31.12.2021
Hajmi4,67 Mb.
#213682
1   ...   208   209   210   211   212   213   214   215   ...   266
Bog'liq
2 5296731884800181221

Appendix A
Pedal to the Metal: Accelerating 
Python
Make it work, make it right, make it fast.
— Kent Beck
This appendix is a tiny peek at some of the options for tweaking the constant factors of your implementations. 
Although this kind of optimization in many cases won’t take the place of proper algorithm design—especially if your 
problems can grow large—making your program run ten times as fast can indeed be useful.
Before calling for external help, you should make sure you’re using Python’s built-in tools to their full potential. 
I’ve given you some pointers throughout the book, including the proper uses of list versus deque and how bisect 
and heapq can give you a great performance boost under the right circumstances. As a Python programmer, you’re 
also lucky enough to have easy access to one of the most advanced and efficient (and efficiently implemented) sorting 
algorithms out there (list.sort), as well as a really versatile and fast hash table (dict). You might even find that 
itertools and functools can give your code a performance boost.
1
Also, when choosing your technology, make sure you optimize only what you must. Optimizations do tend to 
make either your code or your tool setup more complicated, so make sure it’s worth it. If your algorithm scales “well 
enough” and your code is “fast enough,” introducing the extension modules in another language such as C might not 
be worth it. What is enough is, of course, up to you to determine. (For some hints on timing and profiling your code, 
see Chapter 2.)
Note that the packages and extensions discussed in this appendix are mainly about optimizing single-processor 
code, either by providing efficiently implemented functionality, by letting you create or wrap extension modules, or 
by simply speeding up your Python interpreter. Distributing your processing to multiple cores and processors can 
certainly also be a big help. The multiprocessing module can be a place to start. If you want to explore this approach, 
you should be able to find a lot of third-party tools for distributed computing as well. For example, you could have  
a look at the Parallel Processing page in the Python Wiki.
In the following pages, I describe a selection of acceleration tools. There are several efforts in this area, and the 
landscape is of course a changing one: New projects appear from time to time, and some old ones fade and die. If you 
think one of these solutions sounds interesting, you should check out its web site and consider the size and activity of 
its community—as well, of course, as your own needs. For web site URLs, see Table 
A-1
 later in the appendix.

Download 4,67 Mb.

Do'stlaringiz bilan baham:
1   ...   208   209   210   211   212   213   214   215   ...   266




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish