Reputation: 7136
I am trying to port my python code to C, but before that i did a performance test, but looks like it did not improve the performance.
First the C program:
#include <stdio.h>
main ()
{
printf("hello world \n");
}
[root@server c]$ gcc test.c
[root@server c]$ time ./a.out
hello world
real 0m0.001s
user 0m0.000s
sys 0m0.000s
Second the Python program:
#!/usr/bin/env python
print "hello world \n"
[root@server c]$ time python test.py
hello world
real 0m0.024s
user 0m0.020s
sys 0m0.003s
Third the Cython...
test.py
print "hello world \n"
[root@server c]$ cython --embed test.py
[root@server c]$ gcc $CFLAGS -I/usr/include/python2.6 -o test test.c -lpython2.6 -lpthread -lm -lutil -ldl
[root@server c]$ time ./test
hello world
real 0m0.024s
user 0m0.019s
sys 0m0.004s
So to me it looks like cython did not really improve any performance. Any ideas why and how i can fix this as cython is supposed to make the python code run faster?
Upvotes: 1
Views: 902
Reputation: 117771
What you are seeing here is no real performance test. You are only doing one tiny operation in your program.
The complete execution time is void. The only thing that matters in the execution time now is overhead. Overhead for the process starting up, and in Python's case overhead for starting the interpreter.
And the final thing, you are testing the performance of I/O here. That itself is a very tricky thing to do because the performance of I/O most often is not limited by the programming language but by the OS.
Upvotes: 13