Floating Point Performance LPC1768 vs LPC4088

LPC1768 µs/100opintfloatdouble
a=b4.54.510
c=a+b973114
c=a*b9.557115
c=a/b1385188
a=sqrt(b) / int->float/double23/26128277
a=log(b) / float/double->int23/299432995
LPC4088 µs/100opintfloatdouble
a=b338
c=a+b79124
c=a*b79105
c=a/b1019149
a=sqrt(b) / int->float/double6/2327178
a=log(b) / float/double->int8/261242721

The silly test

#include "mbed.h"


void floatPerf()
{
#define FTEST
#ifdef FTEST
#define FLT float
#else
#define FLT int32_t
#endif

    const int n=10;
    FLT a[n];
    FLT b[n];
    FLT c[n*n];
    double d[n*n];
    float disco = 0.0;

    for(int i=0; i<n; ++i) {
        a[i]=i*-12.3-4.5;
        b[i]=i*12.3+4.5;
    }

    while(1) {
        wait_ms(500);
        disco = 0.0;
        
        uint32_t t1 = us_ticker_read();
        for(int i=0; i<n; ++i)
            for(int j=0; j<n; ++j)
                c[i*n+j]= a[j];
        uint32_t te = us_ticker_read()-t1;
        for(int i=0; i<n*n; ++i) disco+=c[i];
        //printf("%f\n",disco);
        
        t1 = us_ticker_read();
        for(int i=0; i<n; ++i)
            for(int j=0; j<n; ++j)
                c[i*n+j]=a[i]+b[j];
        uint32_t ts = us_ticker_read()-t1;
        for(int i=0; i<n*n; ++i) disco-=c[i];
        //printf("%f\n",disco);
        
        t1 = us_ticker_read();
        for(int i=0; i<n; ++i)
            for(int j=0; j<n; ++j)
                c[i*n+j]=a[i]*b[j];
        uint32_t tm = us_ticker_read()-t1;
        for(int i=0; i<n*n; ++i) disco+=c[i];
        //printf("%f\n",disco);
        
        t1 = us_ticker_read();
        for(int i=0; i<n; ++i)
            for(int j=0; j<n; ++j)
                c[i*n+j]=a[i]/b[j];
        uint32_t td = us_ticker_read()-t1;
        for(int i=0; i<n*n; ++i) disco-=c[i];
        //printf("%f\n",disco);
        
        t1 = us_ticker_read();
        for(int i=0; i<n; ++i)
            for(int j=0; j<n; ++j)
#ifdef FTEST
                {c[i*n+j]=sqrt(b[j]); /*printf("%f sqrt %f\n",b[j],c[i*n+j]);*/}
#else
                d[i*n+j]=c[i*n+j];
#endif
        uint32_t tsq = us_ticker_read()-t1;
        for(int i=0; i<n*n; ++i) 
#ifdef FTEST 
        disco+=c[i];
#else
        disco+=d[i];
#endif
        //printf("%f\n",disco);
        
        t1 = us_ticker_read();
        for(int i=0; i<n; ++i)
            for(int j=0; j<n; ++j)
#ifdef FTEST
                {c[i*n+j]=log(b[j]); /*printf("%f log %f\n",b[j],c[i*n+j]);*/}
#else
                c[i*n+j]=d[i*n+j];
#endif
        uint32_t tln = us_ticker_read()-t1;
        for(int i=0; i<n*n; ++i) disco-=c[i];

        printf("%f %u %u %u %u %u %u\n",disco,te,ts,tm,td,tsq,tln);
    }
}

int main()
{
    floatPerf();
    return 0;
}


Please log in to post comments.