From: Pujo A. <aj...@gm...> - 2005-12-05 13:15:27
|
Thanks Marcelo, You're right, because looping in python is frustrating. Now it is fast. I have a few problems: my compiler doesn't allow me to define type of variable like this: for (int i =3D 0; i<10; i++){ //mycode } I should use : int i =3D 0; for (i =3D 0; i<10; i++){ //mycode } Is that standard? Thanks, pujo On 12/5/05, Marcelo Matus <mm...@ac...> wrote: > > You are not just comparing the swig/C++, you have a huge for loop in > there. > > > Try the other way, create a function in C++ with the loop inside > and the call it from python. > > also,look at the profiletest_runme.py in the > SWIG/Examples/test-suite/python for > ideas of comparing using loops. > > Marcelo > > > Pujo Aji wrote: > > > Hello All, Marcelo, > > > > > > I manage to use visual studio express C++ (.Net Framework 2) compiler > > with swig and python. > > By tweaking pyConfig, installing SDK Platform etc. > > I can run the runme.py in "simple" example. > > > > I have 2 questions : > > 1. Concerning compiling simple.c and simple_wrap.c: > > The last thing that I need is simple.py and _simple.dll is this > > correct ? > > Because in the tutorial it mentioned simple.o and simple.so which > > I can't find these files in my computer (win xp) > > > > 2. Concerning swig speed. > > I found something very interesting. > > I create a function in C++ and use swig to wrap it. > > After getting simple.dll and simple.py. I can use it in my main python > > program (runme.py). > > I compare the speed between : pure C++, C++wrap with swig, pure > > python, and python with psyco. > > This is the result: > > > > *pure C++ : 1 second > > > > python without psyco: > > C++wrap with swig: 13.76 second > > pure python: 37.19 second > > > > python with psyco: > > C++ wrap with swig: 14.55 second > > pure python: 15 second > > > > Strange, I thought at the first time: > > 1. with psyco the speed of C++ wrap with swig is almost the same speed. > > 2. pure C++ is much much faster than C++ wrap with swig and used in > > python ??? > > > > Note : > > * for pure C++, I can't test until the unit in millisecond, but I > > minimize this problem by using problem that make pure python and > > C++wrap with swig produce a couple of seconds. > > > > Looking forward to your responds > > Sincerely Yours, > > pujo > > . > > > >------------------------------------------------------------------------ > > > ># file: example.py > > > >import example > >import time > >import psyco > >psyco.full() > > > >def fact(n): > > f =3D 1 > > while( n>1): > > f *=3D n > > n -=3D 1 > > return f > > > >## Call our gcd() function > ># > >#x =3D 42 > >#y =3D 105 > >#g =3D example.gcd(x,y) > >#print "The gcd of %d and %d is %d" % (x,y,g) > ># > >## Manipulate the Foo global variable > ># > >## Output its current value > >#print "Foo =3D ", example.cvar.Foo > ># > >## Change its value > >#example.cvar.Foo =3D 3.1415926 > ># > >## See if the change took effect > >#print "Foo =3D ", example.cvar.Foo > > > >start =3D time.time() > >sum =3D 0 > >for i in range(10000000): > > sum+=3Dexample.fact(10) > >stop =3D time.time() > >print sum > >print 'wrap c++ time,', stop-start > > > > > >start =3D time.time() > >sum =3D 0 > >for i in range(10000000): > > sum+=3Dfact(10) > >stop =3D time.time() > >print 'python time,', stop-start > > > > > > > > > > > > > > > > > > |