Extensions in C/C++, System Calls, and C/C++ Libraries
The last few chapters have shown us many machine learning and scientific computing libraries. Many of these libraries are not written in pure Python because of code reuse from existing libraries, or for performance reasons. In this chapter, we will learn how we can do some of this ourselves by creating C/C++ extensions.
In Chapter 12, Performance – Tracking and Reducing Your Memory and CPU Usage, we saw that the cProfile
module is about 10 times faster than the profile
module, which indicates that at least some C extensions are faster than their pure Python equivalents. This chapter will not focus on performance that much, however. The goal here is interaction with non-Python libraries. To paraphrase Linus Torvalds, any performance improvement will just be a completely unintentional side effect.
If performance is your main goal, you really should not be looking at writing a C/C++ extension...