Skip to content

Commit

Permalink
Merge wasmerio#11
Browse files Browse the repository at this point in the history
11: test(benchmarks) Improve `life` & `wagon`, create `wasmer` r=Hywan a=Hywan

Use Life's benchmark cases to improve all the benchmarks.

Co-authored-by: Ivan Enderlin <[email protected]>
  • Loading branch information
bors[bot] and Hywan committed May 28, 2019
2 parents 10eef52 + d6c8dac commit d6f8da7
Show file tree
Hide file tree
Showing 14 changed files with 123 additions and 48 deletions.
35 changes: 20 additions & 15 deletions benchmarks/life/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,46 @@ package wasmer_test

import (
life "github.com/perlin-network/life/exec"
"github.com/wasmerio/go-ext-wasm/wasmer"
"io/ioutil"
"path"
"runtime"
"testing"
)

const N = 100000

func GetBytes() []byte {
func GetBytes(wasmFile string) []byte {
_, filename, _, _ := runtime.Caller(0)
modulePath := path.Join(path.Dir(filename), "testdata", "benchmarks", "nbody.wasm")
modulePath := path.Join(path.Dir(filename), "testdata", "benchmarks", wasmFile)

bytes, _ := wasmer.ReadBytes(modulePath)
bytes, _ := ioutil.ReadFile(modulePath)

return bytes
}

func BenchmarkWasmer(b *testing.B) {
wasmBytes := GetBytes()
func Benchmark_Life_Nbody(b *testing.B) {
benchmarkLife(b, "nbody.wasm", "main", N)
}

for i := 0; i < b.N; i++ {
instance, _ := wasmer.NewInstance(wasmBytes)
result, _ := instance.Exports["main"](N)
func Benchmark_Life_Fibonacci_Recursive(b *testing.B) {
benchmarkLife(b, "fib_recursive.wasm", "app_main")
}

_ = result
}
func Benchmark_Life_Pollard_Rho_128(b *testing.B) {
benchmarkLife(b, "pollard_rho_128.wasm", "app_main")
}

func Benchmark_Life_Snappy_Compress(b *testing.B) {
benchmarkLife(b, "snappy_compress.wasm", "app_main")
}

func BenchmarkLife(b *testing.B) {
wasmBytes := GetBytes()
func benchmarkLife(b *testing.B, wasmFile string, exportName string, exportValues ...int64) {
wasmBytes := GetBytes(wasmFile)

for i := 0; i < b.N; i++ {
vm, _ := life.NewVirtualMachine(wasmBytes, life.VMConfig{}, &life.NopResolver{}, nil)
entryID, _ := vm.GetFunctionExport("main")
result, _ := vm.Run(entryID, N)
entryID, _ := vm.GetFunctionExport(exportName)
result, _ := vm.Run(entryID, exportValues...)

_ = result
}
Expand Down
4 changes: 3 additions & 1 deletion benchmarks/life/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ go 1.12
replace github.com/go-interpreter/wagon v0.0.0 => github.com/perlin-network/wagon v0.3.1-0.20180825141017-f8cb99b55a39

require (
github.com/kr/pretty v0.1.0 // indirect
github.com/perlin-network/life v0.0.0-20190521143330-57f3819c2df0
github.com/wasmerio/go-ext-wasm v0.0.0-20190527154049-20a5840a9e4f
golang.org/x/sync v0.0.0-20190423024810-112230192c58 // indirect
google.golang.org/appengine v1.6.0 // indirect
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
)
20 changes: 12 additions & 8 deletions benchmarks/life/go.sum
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/perlin-network/life v0.0.0-20190521143330-57f3819c2df0 h1:fP9xTEHvfuArvWXQhRDYHSBNX/3ZaAfFKlxzpZtUsqs=
github.com/perlin-network/life v0.0.0-20190521143330-57f3819c2df0/go.mod h1:z/EH0mO9zbeuTT5NX4u2VqVSG8y2vDQXz6iDKxikW2I=
github.com/perlin-network/wagon v0.3.1-0.20180825141017-f8cb99b55a39 h1:CYHXy6CWxxL7ugjvCbTELOm2j5iRLEWGPl3AQYvretw=
github.com/perlin-network/wagon v0.3.1-0.20180825141017-f8cb99b55a39/go.mod h1:zHOMvbitcZek8oshsMO5VpyBjWjV9X8cn8WTZwdebpM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/vmihailenco/msgpack v4.0.4+incompatible h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
github.com/vmihailenco/msgpack v4.0.4+incompatible/go.mod h1:fy3FlTQTDXWkZ7Bh6AcGMlsjHatGryHQYUTf1ShIgkk=
github.com/wasmerio/go-ext-wasm v0.0.0-20190522133517-c52507aa3614 h1:8/q1Gs0ujWErtQYfjQwUC2zwtx6WcWJ09vvoHdw3ivM=
github.com/wasmerio/go-ext-wasm v0.0.0-20190522133517-c52507aa3614/go.mod h1:eMc2spdUoaytBSiXb6oJVSyzkYL2TePhYiv09mmP9lA=
github.com/wasmerio/go-ext-wasm v0.0.0-20190527154049-20a5840a9e4f h1:xyPd41z0V3O555xDX+iUi69mbM3czwF99ALHI+UBphw=
github.com/wasmerio/go-ext-wasm v0.0.0-20190527154049-20a5840a9e4f/go.mod h1:UkqsV9/yC6+lwjqMq7fpBrxhhGKH0VzqT7nAFR4jS9I=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225 h1:kNX+jCowfMYzvlSvJu5pQWEmyWFrBXJ3PBy10xKMXK8=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
google.golang.org/appengine v1.6.0 h1:Tfd7cKwKbFRsI8RMAD3oqqw7JPFRrvFlOsfbgVkjOOw=
google.golang.org/appengine v1.6.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
41 changes: 23 additions & 18 deletions benchmarks/wagon/benchmarks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,49 @@ import (
"fmt"
wagon_exec "github.com/go-interpreter/wagon/exec"
wagon_wasm "github.com/go-interpreter/wagon/wasm"
"github.com/wasmerio/go-ext-wasm/wasmer"
"io/ioutil"
"path"
"runtime"
"testing"
)

const N = 100000

func GetBytes() []byte {
func GetBytes(wasmFile string) []byte {
_, filename, _, _ := runtime.Caller(0)
modulePath := path.Join(path.Dir(filename), "testdata", "benchmarks", "nbody.wasm")
modulePath := path.Join(path.Dir(filename), "testdata", "benchmarks", wasmFile)

bytes, _ := wasmer.ReadBytes(modulePath)
bytes, _ := ioutil.ReadFile(modulePath)

return bytes
}

func BenchmarkWasmer(b *testing.B) {
wasmBytes := GetBytes()

for i := 0; i < b.N; i++ {
instance, _ := wasmer.NewInstance(wasmBytes)
result, _ := instance.Exports["main"](N)

_ = result
}
}

func BenchmarkWagon(b *testing.B) {
wasmBytes := GetBytes()
func benchmarkWagon(b *testing.B, wasmFile string, exportName int64, exportValues ...uint64) {
wasmBytes := GetBytes(wasmFile)

for i := 0; i < b.N; i++ {
module, _ := wagon_wasm.ReadModule(bytes.NewReader(wasmBytes), func(name string) (*wagon_wasm.Module, error) {
return nil, fmt.Errorf("Module %q unknown.", name)
})
vm, _ := wagon_exec.NewVM(module)
result, _ := vm.ExecCode(1, uint64(N))
result, _ := vm.ExecCode(exportName, exportValues...)

_ = result
}
}

func Benchmark_Wagon_Nbody(b *testing.B) {
benchmarkWagon(b, "nbody.wasm", 1, uint64(N))
}

func Benchmark_Wagon_Fibonacci_Recursive(b *testing.B) {
benchmarkWagon(b, "fib_recursive.wasm", 1)
}

func Benchmark_Wagon_Pollard_Rho_128(b *testing.B) {
benchmarkWagon(b, "pollard_rho_128.wasm", 0)
}

func Benchmark_Wagon_Snappy_Compress(b *testing.B) {
benchmarkWagon(b, "snappy_compress.wasm", 0)
}
5 changes: 1 addition & 4 deletions benchmarks/wagon/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module github.com/wasmerio/go-ext-wasm/benchmarks-wagon

go 1.12

require (
github.com/go-interpreter/wagon v0.4.0
github.com/wasmerio/go-ext-wasm v0.0.0-20190527154049-20a5840a9e4f
)
require github.com/go-interpreter/wagon v0.4.0
46 changes: 46 additions & 0 deletions benchmarks/wasmer/benchmarks_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package wasmer_test

import (
"github.com/wasmerio/go-ext-wasm/wasmer"
"path"
"runtime"
"testing"
)

const N = 100000

func GetBytes(wasmFile string) []byte {
_, filename, _, _ := runtime.Caller(0)
modulePath := path.Join(path.Dir(filename), "testdata", "benchmarks", wasmFile)

bytes, _ := wasmer.ReadBytes(modulePath)

return bytes
}

func benchmarkWasmer(b *testing.B, wasmFile string, exportName string, exportValues ...interface{}) {
wasmBytes := GetBytes(wasmFile)

for i := 0; i < b.N; i++ {
instance, _ := wasmer.NewInstance(wasmBytes)
result, _ := instance.Exports[exportName](exportValues...)

_ = result
}
}

func Benchmark_Wasmer_Nbody(b *testing.B) {
benchmarkWasmer(b, "nbody.wasm", "main", N)
}

func Benchmark_Wasmer_Fibonacci_Recursive(b *testing.B) {
benchmarkWasmer(b, "fib_recursive.wasm", "app_main")
}

func Benchmark_Wasmer_Pollard_Rho_128(b *testing.B) {
benchmarkWasmer(b, "pollard_rho_128.wasm", "app_main")
}

func Benchmark_Wasmer_Snappy_Compress(b *testing.B) {
benchmarkWasmer(b, "snappy_compress.wasm", "app_main")
}
5 changes: 5 additions & 0 deletions benchmarks/wasmer/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/wasmerio/go-ext-wasm/benchmarks-wasmer

go 1.12

require github.com/wasmerio/go-ext-wasm v0.0.0-20190527154049-20a5840a9e4f
6 changes: 6 additions & 0 deletions benchmarks/wasmer/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
github.com/wasmerio/go-ext-wasm v0.0.0-20190527154049-20a5840a9e4f h1:xyPd41z0V3O555xDX+iUi69mbM3czwF99ALHI+UBphw=
github.com/wasmerio/go-ext-wasm v0.0.0-20190527154049-20a5840a9e4f/go.mod h1:UkqsV9/yC6+lwjqMq7fpBrxhhGKH0VzqT7nAFR4jS9I=
1 change: 1 addition & 0 deletions benchmarks/wasmer/testdata
8 changes: 6 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ go go-build-args='':
*)
dylib_extension="so"
esac
#test -f libwasmer_runtime_c_api.${dylib_extension} && rm libwasmer_runtime_c_api.${dylib_extension}
#ln -s ../target/release/deps/libwasmer_runtime_c_api-*.${dylib_extension} libwasmer_runtime_c_api.${dylib_extension}
test -f libwasmer_runtime_c_api.${dylib_extension} || \
ln -s ../target/release/deps/libwasmer_runtime_c_api-*.${dylib_extension} libwasmer_runtime_c_api.${dylib_extension}
go build -ldflags="-r $(pwd)" -v {{go-build-args}} .
# Generate cgo debug objects.
Expand All @@ -39,6 +39,10 @@ test:
# Run the long examples.
go test -test.v $(find . -type f \( -name "example_*_test.go" \! -name "example_import_test.go" \) )
# Run benchmarks. Subjects can be `wasmer`, `wagon` or `life`. Filter is a regex to select the benchmarks.
bench subject='wagon' filter='.*':
cd benchmarks/{{subject}} && go test -bench '{{filter}}' benchmarks_test.go
# Local Variables:
# mode: makefile
# End:
Binary file not shown.
Empty file modified wasmer/test/testdata/benchmarks/nbody.wasm
100755 → 100644
Empty file.
Binary file not shown.
Binary file not shown.

0 comments on commit d6f8da7

Please sign in to comment.