Skip to content

Commit

Permalink
Merge pull request #2 from D0peX/master
Browse files Browse the repository at this point in the history
Logging with logfile
  • Loading branch information
NinjaJc01 authored Nov 11, 2018
2 parents 4a1129c + 0eddb35 commit 699f92d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# ignoring log.txt
log.txt
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,4 @@ https://golang.org/
```GOARCH=arm64 GOOS=linux go build ./parallel/egoParallel.go```
Would build for arm64, linux (raspi etc, sometimes you may need just arm)
See entries in bold for supported OS and Architectures out of the box: https://gist.github.com/asukakenji/f15ba7e588ac42795f421b48b8aede63
1. Make sure you FILTER the output:
\*NIX ```| grep e```
Powershell ```| Select-String e```
CMD ```| find "e"```
1. New: try -hard as a flag, sets the iterations and precision higher to give your CPU a workout! Overrides any set precision or iterations!
32 changes: 27 additions & 5 deletions parallel/egoParallel.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package main
import (
"flag"
"fmt"
"log"
"os"
"time"

"github.com/ericlagergren/decimal"
Expand All @@ -16,10 +18,23 @@ var (
)

func main() {
// Options
precPtr := flag.Int("p", 10001, "Precision for calculations")
iterPtr := flag.Uint64("i", 1625, "Value of infinity")
hard := flag.Bool("hard", false, "Stress your hardware more, more iterations! Forces set iterations and precison, overiding any set.")
debug := flag.Bool("debug", false, "Used for debugging. This will write to log.txt")
flag.Parse()

// Logger
f, err := os.OpenFile("log.txt",
os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
if err != nil {
log.Println(err)
}
defer f.Close()
logger := log.New(f, "eGoDecimal ", log.LstdFlags)

// Iterations
precision = *precPtr
iterations = *iterPtr
if *hard {
Expand All @@ -28,7 +43,7 @@ func main() {
}
start := time.Now()
channel = make(chan *decimal.Big, iterations)
//go series(0,*iterPtr)
//go series(0, *iterPtr)
var answer = decimal.WithPrecision(precision).SetUint64(0)
for i := uint64(1); i < iterations; i++ {
go series(i-1, i)
Expand All @@ -38,10 +53,17 @@ func main() {
//fmt.Print(".")
//time.Sleep(time.Millisecond*5)
}
fmt.Println()
fmt.Println(answer)
fmt.Print("Time: ")
fmt.Println(time.Now().Sub(start))

// Logging
if *debug {
logger.Println(answer)
logger.Printf("\nRun Time: %v\n", time.Now().Sub(start))
}

// Print result to console and write to log
logger.Printf("\nRun Time: %v\n", time.Now().Sub(start))
fmt.Printf("Run Time: %v\n", time.Now().Sub(start))

}
func series(lower, upper uint64) {
var res = decimal.WithPrecision(precision).SetUint64(0)
Expand Down

0 comments on commit 699f92d

Please sign in to comment.