00001 #include "scs.h"
00002 #include "scs_private.h"
00003
00004
00005
00006 #include <stdio.h>
00007 #include <stdlib.h>
00008 #include <stdarg.h>
00009 #include <math.h>
00010 #include "tbx_timing.h"
00011 #ifdef HAVE_GMP_H
00012 #include <gmp.h>
00013 #endif
00014 #ifdef HAVE_MPFR_H
00015 #include <mpfr.h>
00016 #endif
00017
00018
00019 #define LOOPS 1000
00020
00021
00022
00023
00024
00025
00026 #define TST_FCT(char, name)\
00027 \
00028 for(i=0; i< LOOPS-1; i++){ \
00029 name;\
00030 } \
00031 TBX_GET_TICK(t1);\
00032 for(i=0; i< LOOPS-1; i++){ \
00033 name;\
00034 } \
00035 TBX_GET_TICK(t2);\
00036 deltat = TBX_TICK_RAW_DIFF(t1, t2); \
00037 printf("%28s : %lld ticks,\t ratio to FP +: %f\n", char, deltat, (double) deltat/tadd);
00038
00039
00040
00041
00042 #define COMPUTE_TADD()\
00043 \
00044 for(i=0; i< LOOPS-1; i++){ \
00045 d3 = double_table[i]*double_table[i+1];\
00046 } \
00047 TBX_GET_TICK(t1);\
00048 for(i=0; i< LOOPS-1; i++){ \
00049 d3 = double_table[i]*double_table[i+1];\
00050 } \
00051 TBX_GET_TICK(t2);\
00052 tadd = TBX_TICK_RAW_DIFF(t1, t2);
00053
00054
00055
00056
00057
00058 int main(){
00059 scs_t n1I;
00060 volatile double d3;
00061 volatile int int_r;
00062 unsigned long long deltat,tadd;
00063 tbx_tick_t t1, t2;
00064 int i;
00065
00066
00067 scs_t scs_table[LOOPS];
00068 #ifdef HAVE_GMP_H
00069 mpf_t mpf_table[LOOPS];
00070 mpf_t a;
00071 #endif
00072 #ifdef HAVE_MPFR_H
00073 mpfr_t mpfr_table[LOOPS];
00074 mpfr_t mpfr_a;
00075 #endif
00076
00077 double double_table[LOOPS];
00078 int int_table[LOOPS];
00079
00080
00081
00082 printf("Random generation ... ");
00083 srand(42);
00084 for(i=0; i<LOOPS; i++){
00085 scs_rand(scs_table[i], 7);
00086 #if 1
00087 scs_table[i]->sign = 1;
00088 #endif
00089 scs_get_d(&double_table[i], scs_table[i]);
00090 int_table[i] = double_table[i];
00091 #ifdef HAVE_GMP_H
00092 mpf_init2(mpf_table[i], (SCS_NB_BITS*SCS_NB_WORDS) );
00093 scs_get_mpf(scs_table[i], mpf_table[i]);
00094 #endif
00095 #ifdef HAVE_MPFR_H
00096 mpfr_init2(mpfr_table[i], (SCS_NB_BITS*SCS_NB_WORDS) );
00097 scs_get_mpfr(scs_table[i], mpfr_table[i]);
00098 #endif
00099 }
00100 printf(" done \n\n");
00101
00102
00103 #ifdef HAVE_GMP_H
00104 mpf_init2(a, (SCS_NB_BITS*SCS_NB_WORDS));
00105 mpf_set(a, mpf_table[1]);
00106 #endif
00107 #ifdef HAVE_MPFR_H
00108 mpfr_init2(mpfr_a, (SCS_NB_BITS*SCS_NB_WORDS));
00109 mpfr_set(mpfr_a, mpfr_table[1], GMP_RNDN);
00110 #endif
00111
00112 printf("These first timings don't mean much\n");
00113 COMPUTE_TADD()
00114 TST_FCT("int a + b ", int_r = int_table[i]+int_table[i+1])
00115 TST_FCT("int a * b ", d3 = int_table[i]*int_table[i+1])
00116 TST_FCT("double a + b ", d3 = double_table[i]+double_table[i+1])
00117 TST_FCT("double a * b ", d3 = double_table[i]*double_table[i+1])
00118 TST_FCT("double a / b ", d3 = double_table[i]/double_table[i+1])
00119 printf("\n");
00120
00121 printf("Here come the meaningful timings\n");
00122
00123 TST_FCT("conversion scs=>doubles ", scs_get_d(&double_table[i], scs_table[i]))
00124 TST_FCT("conversion doubles=>scs ", scs_set_d(n1I, double_table[i]))
00125 TST_FCT("scs_add ", scs_add(n1I, scs_table[i], scs_table[i+1]))
00126 TST_FCT("scs_sub ", scs_sub(n1I, scs_table[i], scs_table[i+1]))
00127 TST_FCT("scs_add_no_renorm ",scs_add_no_renorm(n1I, scs_table[i], scs_table[i+1]))
00128 TST_FCT("scs_mul ", scs_mul(n1I, scs_table[i], scs_table[i+1]))
00129 TST_FCT("scs_mul_ui ", scs_mul_ui(scs_table[i], 31242436))
00130 TST_FCT("scs_square ", scs_square(n1I, scs_table[i]))
00131
00132 TST_FCT("add + mul scs ", scs_mul(n1I, scs_table[i], scs_table[i+1]); scs_add(n1I, n1I, scs_table[i]))
00133
00134 TST_FCT("renormalization scs ", scs_renorm(scs_table[i]))
00135 TST_FCT("scs_div ", scs_div(n1I, scs_table[i], scs_table[i+1]))
00136 printf("\n");
00137
00138 #ifdef HAVE_GMP_H
00139
00140 TST_FCT("Conversion mpf=>double", double_table[i] = mpf_get_d(mpf_table[i]))
00141 TST_FCT("Conversion double=>mpf ", mpf_set_d(a, double_table[i]))
00142 TST_FCT("Addition mpf ", mpf_add(a, mpf_table[i], mpf_table[i+1]))
00143 TST_FCT("Multiplication mpf ", mpf_mul(a, mpf_table[i], mpf_table[i+1]))
00144 TST_FCT("Multiplication_with_int mpf ", mpf_mul_ui(a, mpf_table[i], 3254353))
00145 TST_FCT("Division mpf ", mpf_div(a, mpf_table[i], mpf_table[i+1]))
00146 printf("\n");
00147 #endif
00148
00149
00150 #ifdef HAVE_MPFR_H
00151
00152 TST_FCT("Conversion mpfr=>double", double_table[i] = mpfr_get_d(mpfr_table[i],GMP_RNDN))
00153 TST_FCT("Conversion double=>mpfr ", mpfr_set_d(mpfr_a, double_table[i],GMP_RNDN))
00154 TST_FCT("Addition mpfr ", mpfr_add(mpfr_a, mpfr_table[i], mpfr_table[i+1],GMP_RNDN))
00155 TST_FCT("Multiplication mpfr ", mpfr_mul(mpfr_a, mpfr_table[i], mpfr_table[i+1],GMP_RNDN))
00156 TST_FCT("Multiplication_with_int mpfr ", mpfr_mul_ui(mpfr_a, mpfr_table[i], 3254353,GMP_RNDN))
00157 TST_FCT("Division mpfr ", mpfr_div(mpfr_a, mpfr_table[i], mpfr_table[i+1],GMP_RNDN))
00158 printf("\n");
00159 #endif
00160
00161
00162
00163
00164 return 0;
00165 }
00166