build, check initial times for go

This commit is contained in:
NunoSempere 2024-02-16 00:57:22 +01:00
parent bfb5c75070
commit 651ade8b47
4 changed files with 28 additions and 5 deletions

View File

@ -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

View File

@ -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

BIN
go/squiggle Executable file

Binary file not shown.

View File

@ -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)
}