build, check initial times for go
This commit is contained in:
parent
bfb5c75070
commit
651ade8b47
16
go/makefile
16
go/makefile
|
@ -1,2 +1,16 @@
|
||||||
run:
|
dev:
|
||||||
go run squiggle.go
|
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
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
- [x] Hello world program
|
- [x] Hello world program
|
||||||
- [x] Look into randomness sources in go
|
- [x] Look into randomness sources in go
|
||||||
- rand/v2 api: <https://pkg.go.dev/math/rand/v2>
|
- 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
BIN
go/squiggle
Executable file
Binary file not shown.
|
@ -6,6 +6,8 @@ import rand "math/rand/v2"
|
||||||
|
|
||||||
var r = rand.New(rand.NewPCG(1, 2))
|
var r = rand.New(rand.NewPCG(1, 2))
|
||||||
|
|
||||||
|
// https://pkg.go.dev/math/rand/v2
|
||||||
|
|
||||||
func sample_unit_uniform() float64 {
|
func sample_unit_uniform() float64 {
|
||||||
return r.Float64()
|
return r.Float64()
|
||||||
}
|
}
|
||||||
|
@ -46,7 +48,13 @@ func sample_to(low float64, high float64) float64 {
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("Hello world!")
|
var n_samples int = 1000000
|
||||||
fmt.Printf("%v\n", r.Float64())
|
// var array_samples [n_samples]float64
|
||||||
fmt.Printf("%v\n", r.NormFloat64())
|
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)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user