Skip to content
Snippets Groups Projects
pi.ino 673 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
    */
    
    
    Neil Gershenfeld's avatar
    Neil Gershenfeld committed
    #define NPTS 100000
    
    Neil Gershenfeld's avatar
    Neil Gershenfeld committed
    
    
    Neil Gershenfeld's avatar
    Neil Gershenfeld committed
    float a,b,c,pi,dt,mflops;
    
    Neil Gershenfeld's avatar
    Neil Gershenfeld committed
    unsigned long i,tstart,tend;
    
    Neil Gershenfeld's avatar
    Neil Gershenfeld committed
    
    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);
    
    Neil Gershenfeld's avatar
    Neil Gershenfeld committed
       Serial.print("NPTS = ");
       Serial.print(NPTS);
       Serial.print(" pi = ");
       Serial.println(pi);
       Serial.print("time = ");
       Serial.print(dt);
       Serial.print(" estimated MFlops = ");
       Serial.println(mflops);
    
    Neil Gershenfeld's avatar
    Neil Gershenfeld committed
       }