The Computer Language
24.11 Benchmarks Game

too simple Go program

source code

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

package main
import ("fmt"; "flag"; "os"; "strconv")

func main () {
    // mtime side-effect
    f, _ := os.Create("./one")
    defer f.Close()    

    n := 0
    flag.Parse()
    if flag.NArg() > 0 { n,_ = strconv.Atoi( flag.Arg(0) ) }
     sum := 0.0
     flip := -1.0
     for i := 1; i <= n; i++ {    
         flip *= -1.0        
         sum += flip / float64(2*i - 1)               
     }                        
    fmt.Printf("%0.9f\n", sum*4.0) 
    
    // mtime side-effect    
    f, _ = os.Create("./two")
    defer f.Close()        
}
    

notes, command-line, and program output

NOTES:
64-bit Ubuntu quad core
go version go1.23.1 linux/amd64
GOAMD64=v2


 Sun, 22 Sep 2024 05:26:47 GMT

MAKE:
/opt/src/go1.23.1/go/bin/go build -o toosimple.go_run toosimple.go

5.40s to complete and log all make actions

COMMAND LINE:
 ./toosimple.go_run 10000000000

PROGRAM OUTPUT:
3.141592653