Trying to compile github.com/dgryski/go-factor, tinygo appeared to hang. I tracked it down to quadratic behaviour with the small primes table. Here is a script that demonstrates this.
// +build ignore
package main
import (
"flag"
"fmt"
)
func main() {
optmax := flag.Int("n", 50000, "maximum number to generate to")
flag.Parse()
maxprime := uint64(*optmax)
fmt.Println("package main\nvar smallPrimes = []int64{")
fmt.Println("\t2,")
for i := uint64(3); i < maxprime; i += 2 {
fmt.Printf("\t%d,\n", i)
}
fmt.Println("}")
}
A small main.go
package main
import "fmt"
func main() {
var totals [4]int
for _, v := range smallPrimes {
totals[v%4]++
}
fmt.Println(totals)
}
And the driver script:
export PATH=~/go/src/go.googlesource.com/go1.16/bin:~/go/src/tinygo.org/tinygo/:$PATH
for i in $(seq 1000 1000 50000); do
echo n=$i
go run ./gen.go -n=$i >primes.go
time (tinygo build -gc=leaking -scheduler=coroutines -target=wasi -o c.wasm) 2>time-$i.out
cat time-$i.out
done
echo "generating data set"
grep 'real' time-*.out |sed 's/time-//; s/.out:real//; s/0m//; s/s$//' |sort -n >inputs.txt
Trying to compile
github.com/dgryski/go-factor, tinygo appeared to hang. I tracked it down to quadratic behaviour with the small primes table. Here is a script that demonstrates this.A small main.go
And the driver script: