Skip to content

Instantly share code, notes, and snippets.

@amrnt
Last active August 29, 2015 14:15
Show Gist options
  • Save amrnt/b1cae7ddc6c5fb8de814 to your computer and use it in GitHub Desktop.
Save amrnt/b1cae7ddc6c5fb8de814 to your computer and use it in GitHub Desktop.
package main
import (
"github.com/robertkrimen/otto"
)
func main() {
vm := otto.New()
vm.Run(`
function fib(n) {
if (n < 2) return n;
return fib(n - 2) + fib(n - 1);
}
console.log(fib(30));
`)
}
function fib(n) {
if (n < 2) return n;
return fib(n - 2) + fib(n - 1);
}
console.log(fib(30));
> time go run main.go
832040
go run main.go 19.10s user 0.94s system 104% cpu 19.098 total
> go build main.go
> time ./main
832040
./main 18.88s user 0.91s system 105% cpu 18.827 total
> time node main.js
832040
node main.js 0.05s user 0.02s system 51% cpu 0.141 total
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment