bench-float.c

Description | Download | Table of Contents | Modules | Compound List | File List | Functions


Overview
Compiler
Documentation
Examples
Misc
Help
IDE & Tools

Download
Install

Links
Projects






00001 /* Benchmark for some float and double operations
00002    Copyright (C) 2001 Free Software Foundation, Inc.
00003    Written by Stephane Carrez (stcarrez@worldnet.fr)    
00004 
00005 This file is free software; you can redistribute it and/or modify it
00006 under the terms of the GNU General Public License as published by the
00007 Free Software Foundation; either version 2, or (at your option) any
00008 later version.
00009 
00010 In addition to the permissions in the GNU General Public License, the
00011 Free Software Foundation gives you unlimited permission to link the
00012 compiled version of this file with other programs, and to distribute
00013 those programs without any restriction coming from the use of this
00014 file.  (The General Public License restrictions do apply in other
00015 respects; for example, they cover modification of the file, and
00016 distribution when not linked into another program.)
00017 
00018 This file is distributed in the hope that it will be useful, but
00019 WITHOUT ANY WARRANTY; without even the implied warranty of
00020 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00021 General Public License for more details.
00022 
00023 You should have received a copy of the GNU General Public License
00024 along with this program; see the file COPYING.  If not, write to
00025 the Free Software Foundation, 59 Temple Place - Suite 330,
00026 Boston, MA 02111-1307, USA.  */
00027 
00045 
00046 #include <benchs.h>
00047 
00048 /* Use global variables to forbid Gcc from doing some optimization.  */
00049 double a = 3.141592;
00050 float f = 3.141592;
00051 
00052 /* Benchmark some floating point operations (mul, add, neg, div, ...).  */
00053 void
00054 bench_float (bench_t *b)
00055 {
00056   long n;
00057   
00058   bench_start (b);
00059   f = f * f;
00060   bench_stop (b);
00061   bench_report (b, "Float mul (%d)", (long) f);
00062 
00063   bench_start (b);
00064   f = f + f;
00065   bench_stop (b);
00066   bench_report (b, "Float add (%d)", (long) f);
00067 
00068   bench_start (b);
00069   f = -f;
00070   bench_stop (b);
00071   bench_report (b, "Float neg (%d)", (long) f);
00072 
00073   bench_start (b);
00074   f = f / 0.1;
00075   bench_stop (b);
00076   bench_report (b, "Float div (%d)", (long) f);
00077 
00078   f = f + 2.0;
00079   bench_start (b);
00080   n = f;
00081   bench_stop (b);
00082   bench_report (b, "Float to long (%d)", n);
00083 
00084   n += 2;
00085   bench_start (b);
00086   f = n;
00087   bench_stop (b);
00088   bench_report (b, "Long to float (%d)", n);
00089 }
00090 
00091 /* Same as bench_float but using 64-bit double.  */
00092 void
00093 bench_double (bench_t *b)
00094 {
00095   long n;
00096   
00097   bench_start (b);
00098   a = a * a;
00099   bench_stop (b);
00100   bench_report (b, "Double mul (%d)", (long) a);
00101 
00102   bench_start (b);
00103   a = a + a;
00104   bench_stop (b);
00105   bench_report (b, "Double add (%d)", (long) a);
00106 
00107   bench_start (b);
00108   a = -a;
00109   bench_stop (b);
00110   bench_report (b, "Double neg (%d)", (long) a);
00111 
00112   bench_start (b);
00113   a = a / 0.1;
00114   bench_stop (b);
00115   bench_report (b, "Double div (%d)", (long) a);
00116 
00117   a = a + 3.1;
00118   bench_start (b);
00119   n = a;
00120   bench_stop (b);
00121   bench_report (b, "Double to long (%d)", n);
00122 
00123   n += 2;
00124   bench_start (b);
00125   a = n;
00126   bench_stop (b);
00127   bench_report (b, "Long to double (%d)", (long) a);
00128 }
00129 
00130 /* Main, run the benchmarks.  */
00131 int
00132 main ()
00133 {
00134   bench_t b;
00135   
00136   bench_init (&b);
00137   bench_float (&b);
00138   bench_double (&b);
00139 
00140   return 0;
00141 }

Description | Download | Table of Contents | Modules | Compound List | File List | Functions

    Last modified,
    Apr 16, 2001
[ Copying ]     [ Feedback to Stephane.Carrez@worldnet.fr ]