Mastering Python High Performance by 2015

Mastering Python High Performance by 2015

Author:2015
Language: eng
Format: epub, mobi
Publisher: Packt Publishing


The preceding code is simple enough. Yes, we could easily improve it by changing the list comprehension expression for a generator. However, for the sake of showing the improvement from the C code, let's not do that. Now, the C code is taking 4.5 seconds on average to run.

Let's now write the check_prime function in C, and let's export it into a shared library (.so file):

#include <stdio.h> #include <math.h> int check_prime(int a) { int c; for ( c = 2 ; c <= sqrt(a) ; c++ ) { if ( a%c == 0 ) return 0; } return 1; }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.