commit 651ade8b4798fb9b3f3c87c3631663ea2d1d827d
parent bfb5c75070b3fe203554dc83524bdf778a697319
Author: NunoSempere <nuno.sempere@protonmail.com>
Date: Fri, 16 Feb 2024 00:57:22 +0100
build, check initial times for go
Diffstat:
4 files changed, 28 insertions(+), 5 deletions(-)
diff --git 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
@@ -1,4 +1,5 @@
- [x] Hello world program
- [x] Look into randomness sources in go
- rand/v2 api: <https://pkg.go.dev/math/rand/v2>
-- [ ]
+- [ ] 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
Binary files differ.
diff --git 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)
+
}