bench-float.c00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00045
00046 #include <benchs.h>
00047
00048
00049 void bench_double (bench_t *b);
00050 void bench_float (bench_t *b);
00051
00052
00053
00054 double a = 3.141592;
00055 float f = 3.141592;
00056
00057
00058 void
00059 bench_float (bench_t *b)
00060 {
00061 long n;
00062
00063 bench_start (b);
00064 f = f * f;
00065 bench_stop (b);
00066 bench_report (b, "Float mul (%d)", (long) f);
00067
00068 bench_start (b);
00069 f = f + f;
00070 bench_stop (b);
00071 bench_report (b, "Float add (%d)", (long) f);
00072
00073 bench_start (b);
00074 f = -f;
00075 bench_stop (b);
00076 bench_report (b, "Float neg (%d)", (long) f);
00077
00078 bench_start (b);
00079 f = f / 0.1;
00080 bench_stop (b);
00081 bench_report (b, "Float div (%d)", (long) f);
00082
00083 f = f + 2.0;
00084 bench_start (b);
00085 n = f;
00086 bench_stop (b);
00087 bench_report (b, "Float to long (%d)", n);
00088
00089 n += 2;
00090 bench_start (b);
00091 f = n;
00092 bench_stop (b);
00093 bench_report (b, "Long to float (%d)", n);
00094 }
00095
00096
00097 void
00098 bench_double (bench_t *b)
00099 {
00100 long n;
00101
00102 bench_start (b);
00103 a = a * a;
00104 bench_stop (b);
00105 bench_report (b, "Double mul (%d)", (long) a);
00106
00107 bench_start (b);
00108 a = a + a;
00109 bench_stop (b);
00110 bench_report (b, "Double add (%d)", (long) a);
00111
00112 bench_start (b);
00113 a = -a;
00114 bench_stop (b);
00115 bench_report (b, "Double neg (%d)", (long) a);
00116
00117 bench_start (b);
00118 a = a / 0.1;
00119 bench_stop (b);
00120 bench_report (b, "Double div (%d)", (long) a);
00121
00122 a = a + 3.1;
00123 bench_start (b);
00124 n = a;
00125 bench_stop (b);
00126 bench_report (b, "Double to long (%d)", n);
00127
00128 n += 2;
00129 bench_start (b);
00130 a = n;
00131 bench_stop (b);
00132 bench_report (b, "Long to double (%d)", (long) a);
00133 }
00134
00135
00136 int
00137 main ()
00138 {
00139 bench_t b;
00140
00141 bench_init (&b);
00142 bench_float (&b);
00143 bench_double (&b);
00144
00145 return 0;
00146 }
|