Skip to content

Commit

Permalink
go
Browse files Browse the repository at this point in the history
Signed-off-by: Takeshi Yoneda <[email protected]>
  • Loading branch information
mathetake committed Dec 21, 2023
1 parent dbf9d34 commit dbf005a
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions internal/integration_test/stdlibs/bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,6 @@ var (
)

func runtBenches(b *testing.B, ctx context.Context, rc wazero.RuntimeConfig, tc testCase) {
runtBench(b, ctx, rc, tc, true)
runtBench(b, ctx, rc, tc, false)
}

func runtBench(b *testing.B, ctx context.Context, rc wazero.RuntimeConfig, tc testCase, compile bool) {
cwd, _ := os.Getwd()
files, err := os.ReadDir(tc.dir)
require.NoError(b, err)
Expand All @@ -157,32 +152,35 @@ func runtBench(b *testing.B, ctx context.Context, rc wazero.RuntimeConfig, tc te
if bin == nil {
continue
}
if compile {
b.Run("Compile/"+fname, func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
r := wazero.NewRuntimeWithConfig(ctx, rc)
_, err := r.CompileModule(ctx, bin)
require.NoError(b, err)
require.NoError(b, r.Close(ctx))
}
})
} else {
r := wazero.NewRuntimeWithConfig(ctx, rc)
wasi_snapshot_preview1.MustInstantiate(ctx, r)
b.Cleanup(func() { r.Close(ctx) })

cm, err := r.CompileModule(ctx, bin)
require.NoError(b, err)
b.Run("Run/"+fname, func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
// Instantiate in the loop as _start cannot be called multiple times.
m, err := r.InstantiateModule(ctx, cm, modCfg)
requireZeroExitCode(b, err)
require.NoError(b, m.Close(ctx))
}
})

for _, compile := range []bool{false, true} {
if compile {
b.Run("Compile/"+fname, func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
r := wazero.NewRuntimeWithConfig(ctx, rc)
_, err := r.CompileModule(ctx, bin)
require.NoError(b, err)
require.NoError(b, r.Close(ctx))
}
})
} else {
r := wazero.NewRuntimeWithConfig(ctx, rc)
wasi_snapshot_preview1.MustInstantiate(ctx, r)
b.Cleanup(func() { r.Close(ctx) })

cm, err := r.CompileModule(ctx, bin)
require.NoError(b, err)
b.Run("Run/"+fname, func(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
// Instantiate in the loop as _start cannot be called multiple times.
m, err := r.InstantiateModule(ctx, cm, modCfg)
requireZeroExitCode(b, err)
require.NoError(b, m.Close(ctx))
}
})
}
}
}
}
Expand Down

0 comments on commit dbf005a

Please sign in to comment.