Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ukma!tut.cis.ohio-state.edu!uccba!uceng!achhabra From: achhabra@uceng.UC.EDU (atul k chhabra) Newsgroups: comp.lang.c Subject: Fortran computes cosine 300 times faster than C (on Sun3) Keywords: Fortran, C, cosine, speed Message-ID: <765@uceng.UC.EDU> Date: 8 Mar 89 06:35:04 GMT Distribution: na Organization: Univ. of Cincinnati, College of Engg. Lines: 57 I chanced upon a segment of code that runs approximately 300 times faster in FORTRAN than in C. I have tried the code on Sun3(OS3.5) and on Sun4(OS4.0) (of course, on Sun4 the -f68881 flag was not used.) The results are similar on both machines. Can anyone enlighten me on this bizzare result? Listing of cosc.c: -------------------------------------------------------------------------------- /* * Compile using: * cc -f68881 -O -o cosc cosc.c -lm. */ #include main() { int i; float tmp; for(i=0;i<262144;i++) tmp=cos(2.5)*cos(2.5)*cos(2.5)*cos(2.5); } -------------------------------------------------------------------------------- Listing of cosf.f -------------------------------------------------------------------------------- c c Compile using: c f77 -f68881 -O -o cosf cosf.f c program cosf integer i real tmp do 10 i=1,262144 tmp=cos(2.5)*cos(2.5)*cos(2.5)*cos(2.5) 10 continue end -------------------------------------------------------------------------------- Timings on Sun3(OS3.5): -------------------------------------------------------------------------------- % time cosc 55.6u 1.0s 1:49 51% 24+8k 12+1io 0pf+0w ^^^^^ % time cosf 0.2u 0.0s 0:00 75% 16+8k 4+0io 0pf+0w ^^^^ -------------------------------------------------------------------------------- =========================================================================== Atul Chhabra, Dept. of Electrical & Computer Engineering, ML 030, University of Cincinnati, Cincinnati, OH 45221-0030. voice: (513)556-4766 INTERNET: achhabra@ucesp1.ece.uc.edu OR achhabra@uceng.uc.edu ===========================================================================