The Computer Language
24.11 Benchmarks Game

too simple C gcc program

source code

/* The Computer Language Benchmarks Game
   https://salsa.debian.org/benchmarksgame-team/benchmarksgame/
*/

#include<stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    // mtime side-effect   
    FILE* f = fopen("./one", "w"); fclose(f);
  
    long n = atol(argv[1]);
    double sum = 0.0;
    double flip = -1.0;
    for (long i = 1; i <= n; i++) {    
        flip *= -1.0;        
        sum += flip / (2*i - 1);               
    }                        
    printf("%.9f\n", sum*4.0);
    
    // mtime side-effect
    f = fopen("./two", "w"); fclose(f); 
    
    return 0;      
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
gcc (Ubuntu 14.2.0-4ubuntu2) 14.2.0


 Tue, 22 Oct 2024 19:26:32 GMT

MAKE:
/usr/bin/gcc -pipe -Wall -O3 -fomit-frame-pointer -march=ivybridge  toosimple.c -o toosimple.gcc_run 
rm toosimple.c

2.40s to complete and log all make actions

COMMAND LINE:
 ./toosimple.gcc_run 10000000000

PROGRAM OUTPUT:
3.141592653