Add Go and Rust algorithm benchmarks

This commit is contained in:
2026-11-23 06:57:31 +08:00
commit f026a77a11
14 changed files with 2101 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
package main
import "syscall/js"
//go:wasmexport recursive
func recursive(n uint64) uint64 {
if n < 2 {
return n
}
return recursive(n-1) + recursive(n-2)
}
//go:wasmexport iterative
func iterative(n uint64) uint64 {
var a, b uint64 = 0, 1
for i := uint64(0); i < n; i++ {
a, b = b, a+b
}
return a
}
//go:wasmexport identity
func identity(n uint64) uint64 {
return n
}
func register(name string, fn func(uint64) uint64) {
js.Global().Set(name, js.FuncOf(func(_ js.Value, args []js.Value) any {
return float64(fn(uint64(args[0].Int())))
}))
}
func main() {
register("goRecursive", recursive)
register("goIterative", iterative)
register("goIdentity", identity)
select {}
}