| Written by Mike James | |||
| Monday, 02 October 2023 | |||
Page 2 of 2
A Python program to make use of the module is very similar to the previous program: import Pi import time if __name__ == '__main__': N=10000000 t1=time.perf_counter() pi=Pi.myPi(1,N) t2=time.perf_counter() print((t2-t1)*1000) print(pi) So how much faster is the C extension than the pure Python? The first thing to say is that this extension should exhibit the maximum speed gain. The pure Python program delegates nothing to any existing C modules and the C extension interacts minimally with Python. The only time lost is initializing the module and making the single call to the function. On a middle-of-the range PC the pure Python program takes 2.5 seconds and the extension takes 50ms, a speedup of 50 times. On a Raspberry Pi 4 the pure Python program takes 3.2 seconds and the extension takes 89ms, a speedup of 35 times. Of course, the speedup you see from using an extension is unlikely to be this great as the task becomes more complex and requires more processing to interface the C and Python code, but it should still be worth the effort. In chapter but not in this extract
Summary
Extending & Embedding Python Using CBy Mike JamesBuy from Amazon. ContentsPreface
<ASIN:B0CK3X93KF> To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Microsoft Adds IQ Layer To Fabric 04/12/2025 Microsoft is adding a "semantic intelligence layer" to Fabric to add that elevates Fabric from a unified data platform to a unified intelligence platform. The announcement says the extra layer w [ ... ] Cursor 2 Enables Multi-Agent Working 18/11/2025 The developers of the AI coding editor Cursor have announced a new version that can be used to work with multiple agents and includes its first coding model. More News
Comments
or email your comment to: comments@i-programmer.info << Prev - Next |
|||
| Last Updated ( Monday, 02 October 2023 ) |
Extending & Embedding Python Using C - Pi