-
Notifications
You must be signed in to change notification settings - Fork 198
/
erc20Benchmark.go
67 lines (57 loc) · 1.71 KB
/
erc20Benchmark.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package benchmarks
import (
"fmt"
"time"
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go/integrationTests/vm/arwen/arwenvm"
)
// ArgErc20Benchmark is the erc20 type benchmark argument used in constructor
type ArgErc20Benchmark struct {
Name string
ScFilename string
Function string
NumRuns int
NumTransfersPerRun int
}
type erc20Benchmark struct {
name string
scFilename string
function string
numRuns int
numTransfersPerRun int
}
// NewErc20Benchmark creates a new benchmark based on erc20 SC execution through Arwen VM
func NewErc20Benchmark(arg ArgErc20Benchmark) *erc20Benchmark {
return &erc20Benchmark{
name: arg.Name,
scFilename: arg.ScFilename,
function: arg.Function,
numRuns: arg.NumRuns,
numTransfersPerRun: arg.NumTransfersPerRun,
}
}
// Run returns the time needed for the benchmark to be run
func (eb *erc20Benchmark) Run() (time.Duration, error) {
if !core.FileExists(eb.scFilename) {
return 0, fmt.Errorf("%w, file %s", ErrFileDoesNotExist, eb.scFilename)
}
result, err := arwenvm.DeployAndExecuteERC20WithBigInt(
eb.numRuns,
eb.numTransfersPerRun,
createTestGasMap(),
eb.scFilename,
eb.function,
)
if err != nil {
return 0, err
}
return getMinimumTimeDuration(result), err
}
// Name returns the benchmark's name
func (eb *erc20Benchmark) Name() string {
return fmt.Sprintf("%s, %d transfer executions, minimum duration", eb.name, eb.numRuns*eb.numTransfersPerRun)
}
// IsInterfaceNil returns true if there is no value under the interface
func (eb *erc20Benchmark) IsInterfaceNil() bool {
return eb == nil
}