MCPcopy Create free account
hub / github.com/evilsocket/sum / benchVM

Function benchVM

service/compiled_benchmark_test.go:87–112  ·  view source on GitHub ↗
(b *testing.B, fname, code string, args []string, expected string, records *storage.Records)

Source from the content-addressed store, hash-verified

85}
86
87func benchVM(b *testing.B, fname, code string, args []string, expected string, records *storage.Records) {
88 oracle := pb.Oracle{
89 Name: fname,
90 Code: code,
91 }
92 compiled, err := compile(&oracle)
93 if err != nil {
94 b.Fatal(err)
95 }
96
97 exp := []byte(nil)
98 if expected != "" {
99 exp = []byte(expected)
100 }
101
102 b.ResetTimer()
103 for i := 0; i < b.N; i++ {
104 if ctx, ret, err := compiled.Run(records, args); err != nil {
105 b.Fatal(err)
106 } else if ctx.IsError() {
107 b.Fatal(ctx.Message())
108 } else if exp != nil && !bytes.Equal(ret, exp) {
109 b.Fatalf("expected '%s', got '%s'", expected, ret)
110 }
111 }
112}
113
114func BenchmarkRunDummy(b *testing.B) {
115 benchVM(b, "dummy", dummyFunc, nil, "", nil)

Callers 6

BenchmarkRunDummyFunction · 0.85
BenchmarkRunAddFunction · 0.85
runFindSimilarFunction · 0.85

Calls 5

compileFunction · 0.85
IsErrorMethod · 0.80
MessageMethod · 0.80
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected