In this situation there isn't one correct answer, or expected result, that I can check for, I'm looking to evaluate the execution time of a function under different conditions, is that still a unit-test?
There's a function embedded in a project I'm working on that executes an addition operation (opAdd) on a virtual machine (the Ethereum VM), the file can be found on the project GitHub page.
This is the specific function responsible for the task:
func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
x, y := stack.pop(), stack.pop()
stack.push(math.U256(x.Add(x, y)))
evm.interpreter.intPool.put(y)
return nil, nil
}
What I'd like to do is create a "unit-test" of sorts to evaluate the execution speed of this operation. To assess this I've modified the function accordingly:
func opAdd(pc *uint64, evm *EVM, contract *Contract, memory *Memory, stack *Stack) ([]byte, error) {
// begin execution time tracking
var startTime = time.Now().UnixNano();
x, y := stack.pop(), stack.pop()
stack.push(math.U256(x.Add(x, y)))
evm.interpreter.intPool.put(y)
// log ellapsed execution time
fmt.Println("execute opAdd consume = ",(time.Now().UnixNano() - startTime))
return nil, nil
}
However, what is missing is the ability to call this function in isolation, and feed it varying amounts of data such that I could evaluate the behaviour of this code under different conditions.
For instance I'd like to see how long it takes to execute with gigabytes, megabytes, etc.
There is some code to check the functioning of the vm here, but it's too complicated for me to understand - I'm new to Golang.
What I'd like to do is write the simplest program possible that could invoke this function, taking as a parameter a varying amount of input data to process. Towards this end I've examined multiple resources, but if an experienced gopher could point me in the right direction it would be immeasurably valuable to advancing my understanding of how to construct practical unit tests.