How can we write a massive - fast module for python? I mean how they write a module like numpy that executes heavy pieces of code in python (which is very slow) so fast? Are they using the C/Python API for that matter? Or it's something else?
-
1Checkout How Fast Numpy Really is and Why?DarrylG– DarrylG2020-05-10 23:29:48 +00:00Commented May 10, 2020 at 23:29
-
3"executes heavy pieces of code in python (which is very slow) so fast?" - because it executes compiled C code, not Python. "Are they using the C/Python API for that matter?" - yes, they are using the C Python API for sure.Marco Bonelli– Marco Bonelli2020-05-10 23:41:17 +00:00Commented May 10, 2020 at 23:41
-
@MarcoBonelli is correct - it's ironic we have modules for Python being written in C.Johnny– Johnny2020-05-11 00:37:39 +00:00Commented May 11, 2020 at 0:37
-
1@Johnny not really. Any language has similar features that permit embedding or calling native code. Performance optimization is a thing. Also, Python itself is written in C.Marco Bonelli– Marco Bonelli2020-05-11 00:38:47 +00:00Commented May 11, 2020 at 0:38
-
@MarcoBonelli of course, it's just interesting that most packages for a language are made in a different language. Like writing an English book in French.Johnny– Johnny2020-05-11 00:41:12 +00:00Commented May 11, 2020 at 0:41
|
Show 1 more comment
1 Answer
Extension can be written in C/C++ with connectors to other python objects and functions.
The official python documentation has a C/C++ API reference