[f2py] f2py speed
"Gabor Kalman" <[email protected]> Sat, 23 Feb 2013 09:29:02 -0800
| Newsgroups | gmane.comp.python.f2py.user |
|---|---|
| Message-ID | <D499804AA7654D839A2179B519F6FEF8@ToshibaGPC> |
This is a multi-part message in MIME format.
--===============0752803790502820169==
Content-type: multipart/alternative;
boundary="----=_NextPart_000_0003_01CE11A8.37C7EC30"
This is a multi-part message in MIME format.
------=_NextPart_000_0003_01CE11A8.37C7EC30
Content-Type: text/plain;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
I=92m a relatively new user of f2py.=20
To test what performance advantage I can get with f2py, I have created =
(a somewhat artificially) simple script.
First I describe it and then I will show the source code.
1. Description:
Take 3 constants (3 integers) and multiply those together in a double =
loop of range of 10,000 (i.e. 10**8 computations).
If I use a PYTHON ONLY scrip, it took 28 sec. (with Windows 7 on a =
Toshiba C655D, Python 27)
If I =93buried=94 the computation in a GFORTRAN sub, it required only =
0.015 sec.
I can=92t find anything wrong with my source codes. So are these results =
plausible?
2. Codes:
module: py_v_p2fy.py
import time
import lib1
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =
PYTHON ONLY =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
def main1(z):
for i in range(10000):
for j in range(10000):
zz=3D2*z =20
start_time =3D time.clock()
z=3D2*3*4
main1(z)
print "done with PYTHON ONLY"
print time.clock() - start_time, "seconds"
print "-----"
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D PYTHON WITH =
F2PY =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
def main2(x1,x2,x3):
lib1.f1(x1,x2,x3)
start_time =3D time.clock()
x1=3D2
x2=3D3
x3=3D4
main2(x1,x2,x3)
print "done with PYTHON WITH F2PY"
print time.clock() - start_time, "seconds"
#=3D=3D=3D=3D=3D=3D=3D=3D
module: lib1.f90
subroutine f1(x1,x2,x3)
integer,intent(IN) :: x1,x2,x3
integer :: z,zz,i,j
do i=3D1,10000
do j=3D1,10000
z =3D x1*x2*x3
zz=3D2*z
end do
end do
end subroutine f1
#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
module (batch-file): run.bat
python C:\Python27\Scripts\f2py.py ^
--build-dir .\tmp ^
--fcompiler=3Dgnu95 ^
-c lib1.f90 -m lib1
pause
------=_NextPart_000_0003_01CE11A8.37C7EC30
Content-Type: text/html;
charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
<HTML><HEAD></HEAD>
<BODY dir=3Dltr>
<DIV dir=3Dltr>
<DIV style=3D"FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV>I=92m a relatively new user of f2py. </DIV>
<DIV>To test what performance advantage I can get with f2py, I have =
created (a=20
somewhat artificially) simple script.</DIV>
<DIV>First I describe it and then I will show the source code.</DIV>
<DIV> </DIV>
<DIV>1. Description:</DIV>
<DIV> </DIV>
<DIV>Take 3 constants (3 integers) and multiply those together in a =
double loop=20
of range of 10,000 (i.e. 10**8 computations).</DIV>
<DIV>If I use a PYTHON ONLY scrip, it took 28 sec. (with Windows 7 on a =
Toshiba=20
C655D, Python 27)</DIV>
<DIV>If I =93buried=94 the computation in a GFORTRAN sub, it required =
only 0.015=20
sec.</DIV>
<DIV> </DIV>
<DIV>I can=92t find anything wrong with my source codes. So are these =
results=20
plausible?</DIV>
<DIV> </DIV>
<DIV>2. Codes:</DIV>
<DIV> </DIV>
<DIV>module: py_v_p2fy.py</DIV>
<DIV> </DIV>
<DIV>import time</DIV>
<DIV>import lib1</DIV>
<DIV>#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =
PYTHON ONLY =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</DI=
V>
<DIV>def main1(z):</DIV>
<DIV> for i in range(10000):</DIV>
<DIV> for j in =
range(10000):</DIV>
<DIV> =20
zz=3D2*z </DIV>
<DIV> </DIV>
<DIV>start_time =3D time.clock()</DIV>
<DIV>z=3D2*3*4</DIV>
<DIV>main1(z)</DIV>
<DIV>print "done with PYTHON ONLY"</DIV>
<DIV>print time.clock() - start_time, "seconds"</DIV>
<DIV>print "-----"</DIV>
<DIV>#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D PYTHON =
WITH F2PY =
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</DIV>
<DIV>def main2(x1,x2,x3):</DIV>
<DIV> lib1.f1(x1,x2,x3)</DIV>
<DIV> </DIV>
<DIV>start_time =3D time.clock()</DIV>
<DIV>x1=3D2</DIV>
<DIV>x2=3D3</DIV>
<DIV>x3=3D4</DIV>
<DIV>main2(x1,x2,x3)</DIV>
<DIV>print "done with PYTHON WITH F2PY"</DIV>
<DIV>print time.clock() - start_time, "seconds"</DIV>
<DIV> </DIV>
<DIV>#=3D=3D=3D=3D=3D=3D=3D=3D</DIV>
<DIV>module: lib1.f90</DIV>
<DIV> </DIV>
<DIV>subroutine f1(x1,x2,x3)</DIV>
<DIV> integer,intent(IN) :: x1,x2,x3</DIV>
<DIV> </DIV>
<DIV> integer :: z,zz,i,j</DIV>
<DIV> </DIV>
<DIV> do i=3D1,10000</DIV>
<DIV> do j=3D1,10000</DIV>
<DIV> =
z =3D=20
x1*x2*x3</DIV>
<DIV> =20
zz=3D2*z</DIV>
<DIV> end do</DIV>
<DIV> end do</DIV>
<DIV>end subroutine f1</DIV>
<DIV> </DIV>
<DIV>#=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D</DIV>
<DIV>module (batch-file): run.bat</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>python C:\Python27\Scripts\f2py.py ^</DIV>
<DIV> --build-dir .\tmp ^</DIV>
<DIV> --fcompiler=3Dgnu95 ^</DIV>
<DIV> -c lib1.f90 -m lib1</DIV>
<DIV>pause</DIV>
<DIV> </DIV>
<DIV> </DIV></DIV></DIV></BODY></HTML>
------=_NextPart_000_0003_01CE11A8.37C7EC30--
--===============0752803790502820169==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
f2py-users mailing list
f2py-users-Y4l6ocDipWCuvFJfX82//[email protected]
http://cens.ioc.ee/mailman/listinfo/f2py-users
--===============0752803790502820169==--