Skip to main content
added 51 characters in body
Source Link
Nulik
  • 4.1k
  • 1
  • 19
  • 30

Do it empirically and compare with other contracts (samples). The most precise measurement you can get.

in core/state_transition.go modify TransitionDb() function to capture current time and, then do a difference with the time after the execution of your contract. Theses are the lines you have to modify:

if contractCreation {
    ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
} else {
    // Increment the nonce for the next transaction
    st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
    ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
}

This is how you would take the time:

start_ts:=time.Now().UnixNano() / int64(time.Millisecond)
if contractCreation {
    ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
} else {
    // Increment the nonce for the next transaction
    st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
    ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
}
end_ts:=time.Now().UnixNano() / int64(time.Millisecond)
log.Info(fmt.Sprintf("Call() time: %v ms",(end_ts-start_ts)))

The above code has not been tested.

Do it empirically and compare with other contracts (samples). The most precise measurement you can get.

in core/state_transition.go capture current time and do a difference after the execution of your contract. Theses are the lines you have to modify:

if contractCreation {
    ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
} else {
    // Increment the nonce for the next transaction
    st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
    ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
}

This is how you would take the time:

start_ts:=time.Now().UnixNano() / int64(time.Millisecond)
if contractCreation {
    ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
} else {
    // Increment the nonce for the next transaction
    st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
    ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
}
end_ts:=time.Now().UnixNano() / int64(time.Millisecond)
log.Info(fmt.Sprintf("Call() time: %v ms",(end_ts-start_ts)))

The above code has not been tested.

Do it empirically and compare with other contracts (samples). The most precise measurement you can get.

in core/state_transition.go modify TransitionDb() function to capture current time , then do a difference with the time after the execution of your contract. Theses are the lines you have to modify:

if contractCreation {
    ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
} else {
    // Increment the nonce for the next transaction
    st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
    ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
}

This is how you would take the time:

start_ts:=time.Now().UnixNano() / int64(time.Millisecond)
if contractCreation {
    ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
} else {
    // Increment the nonce for the next transaction
    st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
    ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
}
end_ts:=time.Now().UnixNano() / int64(time.Millisecond)
log.Info(fmt.Sprintf("Call() time: %v ms",(end_ts-start_ts)))

The above code has not been tested.

Source Link
Nulik
  • 4.1k
  • 1
  • 19
  • 30

Do it empirically and compare with other contracts (samples). The most precise measurement you can get.

in core/state_transition.go capture current time and do a difference after the execution of your contract. Theses are the lines you have to modify:

if contractCreation {
    ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
} else {
    // Increment the nonce for the next transaction
    st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
    ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
}

This is how you would take the time:

start_ts:=time.Now().UnixNano() / int64(time.Millisecond)
if contractCreation {
    ret, _, st.gas, vmerr = evm.Create(sender, st.data, st.gas, st.value)
} else {
    // Increment the nonce for the next transaction
    st.state.SetNonce(msg.From(), st.state.GetNonce(sender.Address())+1)
    ret, st.gas, vmerr = evm.Call(sender, st.to(), st.data, st.gas, st.value)
}
end_ts:=time.Now().UnixNano() / int64(time.Millisecond)
log.Info(fmt.Sprintf("Call() time: %v ms",(end_ts-start_ts)))

The above code has not been tested.