Skip to content
Snippets Groups Projects
pi.ino 563 B
Newer Older
  • Learn to ignore specific revisions
  • Neil Gershenfeld's avatar
    Neil Gershenfeld committed
    /*
    * pi.ino
    * Neil Gershenfeld 12/20/20
    * pi calculation benchmark
    * pi = 3.14159265358979323846
    */
    
    #define NPTS 1000000
    
    int i;
    
    Neil Gershenfeld's avatar
    Neil Gershenfeld committed
    float a,b,c,pi,dt,mflops;
    
    Neil Gershenfeld's avatar
    Neil Gershenfeld committed
    unsigned long tstart,tend;
    
    void setup() {
       Serial.begin(115200);
       }
    
    void loop() {
       tstart = millis();
       a = 0.5;
       b = 0.75;
       c = 0.25;
       pi = 0;
       for (i = 1; i <= NPTS; ++i)
          pi += a/((i-b)*(i-c));
       tend = millis();
       dt = (tend-tstart)/1000.0;
       mflops = NPTS*5.0/(dt*1e6);
       printf("NPTS = %d, pi = %f\n",NPTS,pi);
       printf("time = %f, estimated MFlops = %f\n",dt,mflops);
       }