diff --git a/go/makefile b/go/makefile index 926757de..6450e8b4 100644 --- a/go/makefile +++ b/go/makefile @@ -1,2 +1,16 @@ -run: +dev: go run squiggle.go + +build: + go build squiggle.go + +build-complex: + go build -ldflags="-s -w" squiggle.go + # https://stackoverflow.com/questions/45003259/passing-an-optimization-flag-to-a-go-compiler + +run: + ./squiggle + +time-linux: + @echo "Running 100x and taking avg time: ./squiggle" + @t=$$(/usr/bin/time -f "%e" -p bash -c 'for i in {0..100}; do ./squiggle; done' 2>&1 >/dev/null | grep real | awk '{print $$2}' ); echo "scale=2; 1000 * $$t / 100" | bc | sed "s|^|Time using 16 threads: |" | sed 's|$$|ms|' && echo diff --git a/go/notes.md b/go/notes.md index fe7dc34f..9adf28ef 100644 --- a/go/notes.md +++ b/go/notes.md @@ -1,4 +1,5 @@ - [x] Hello world program - [x] Look into randomness sources in go - rand/v2 api: -- [ ] +- [ ] Test with a million samples of a simple lognormal, just to get a sense of speed +- [ ] Add mixture distribution diff --git a/go/squiggle b/go/squiggle new file mode 100755 index 00000000..1c942b3f Binary files /dev/null and b/go/squiggle differ diff --git a/go/squiggle.go b/go/squiggle.go index eb563a5e..e7990ba6 100644 --- a/go/squiggle.go +++ b/go/squiggle.go @@ -6,6 +6,8 @@ import rand "math/rand/v2" var r = rand.New(rand.NewPCG(1, 2)) +// https://pkg.go.dev/math/rand/v2 + func sample_unit_uniform() float64 { return r.Float64() } @@ -46,7 +48,13 @@ func sample_to(low float64, high float64) float64 { } func main() { - fmt.Println("Hello world!") - fmt.Printf("%v\n", r.Float64()) - fmt.Printf("%v\n", r.NormFloat64()) + var n_samples int = 1000000 + // var array_samples [n_samples]float64 + var avg float64 = 0 + for i := 0; i < n_samples; i++ { + avg += sample_to(1, 10) + } + avg = avg / float64(n_samples) + fmt.Printf("%v\n", avg) + }