l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 7: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2006 Feb 17 13:49

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
[vox-tech] benchmarking (again)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[vox-tech] benchmarking (again)



I'm benchmarking doubles versus floats using C++, C, and java on Cygwin.

Here's the code for C++:


   // double.cc and double.c
   #define REPETITIONS 1000000

   int main( void )
   {
      for ( int i=0; i<REPETITIONS; ++i)
      {
         double epsilon = 1.0E30;
         double one     = 1.0;

         do {
            epsilon /= 2.0;
         } while ( one + epsilon > one );
      }
      return 0;
   }


   // float.cc and float.c
   #define REPETITIONS 1000000
   int main( void )
   {
      for ( int i=0; i<REPETITIONS; ++i)
      {
         float epsilon = 1.0E30F;
         float one     = 1.0F;

         do {
            epsilon /= 2.0F;
         } while ( one + epsilon > one );
      }

      return 0;
   }


which was compiled with:

   OPTIMIZE = -O3 -funroll-loops -fno-math-errno -fno-trapping-math \
      -fno-signaling-nans -funsafe-math-optimizations


and here's Double.java:

   class Double
   {
      public static void main( String[] args )
      {
         final int REPETITIONS=1000000;

         for ( int i=0; i<REPETITIONS; ++i)
         {
            double epsilon = 1.0E30;
            double one     = 1.0;

            do {
               epsilon /= 2.0;
            } while ( one + epsilon > one );
         }
      }
   }


with Float.java being defined similarly modulo some "F's".


Here are the results for the C++ (user time):

            double.cc   float.cc
            1.593       1.577
            1.608       1.608
            1.577       1.577
            1.499       1.515
            1.483       1.546
            1.561       1.546
            1.561       1.546
            1.561       1.499
            1.468       1.561
   average: 1.546       1.553
   std dev: 0.050       0.033

   high val 1.596       1.586
   low val  1.496       1.520

Although double beats out float, the difference is within experimental
error (the error bars for the timings overlap).


The timings for Float.java and Double.java are wierd...

   $ time java Float
   real    0m1.365s
   user    0m0.015s
   sys     0m0.061s

   $ time java Double
   real    0m1.318s
   user    0m0.015s
   sys     0m0.015s

What am I to make of the user time here?

And although I didn't show the "real" time for C++, the java real time is
lower than all the real times for the C++ trials.

How can this be?  I thought that java does stuff like initializing all basic
datatypes to "0" upon instantiation.  And I've read that java allocates
memory for all data items on the heap, which is never stored in L1 cache
while for C and C++, temporary objects are often put into the L1 cache.

How is java real time faster than C++ real time here?

Pete
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.