2020-05-16 20:26:00 +00:00
|
|
|
package initialsync
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkStateMachine_trigger(b *testing.B) {
|
2020-05-27 09:13:41 +00:00
|
|
|
sm := newStateMachineManager()
|
2020-05-16 20:26:00 +00:00
|
|
|
|
2020-05-27 09:13:41 +00:00
|
|
|
handlerFn := func(m *stateMachine, in interface{}) (id stateID, err error) {
|
2020-05-16 20:26:00 +00:00
|
|
|
response, ok := in.(*fetchRequestParams)
|
|
|
|
if !ok {
|
|
|
|
return 0, errInputNotFetchRequestParams
|
|
|
|
}
|
|
|
|
_ = response.count
|
|
|
|
return stateScheduled, nil
|
|
|
|
}
|
|
|
|
|
2020-05-27 09:13:41 +00:00
|
|
|
sm.addEventHandler(eventTick, stateNew, handlerFn)
|
|
|
|
sm.addEventHandler(eventTick, stateScheduled, handlerFn)
|
|
|
|
sm.addEventHandler(eventTick, stateDataParsed, handlerFn)
|
|
|
|
sm.addEventHandler(eventTick, stateSkipped, handlerFn)
|
|
|
|
sm.addEventHandler(eventTick, stateSent, handlerFn)
|
|
|
|
sm.addStateMachine(64)
|
2020-05-16 20:26:00 +00:00
|
|
|
|
|
|
|
b.ReportAllocs()
|
|
|
|
b.ResetTimer()
|
|
|
|
|
|
|
|
for i := 0; i < b.N; i++ {
|
|
|
|
data := &fetchRequestParams{
|
|
|
|
start: 23,
|
|
|
|
count: 32,
|
|
|
|
}
|
2020-05-27 09:13:41 +00:00
|
|
|
err := sm.machines[64].trigger(eventTick, data)
|
2020-05-16 20:26:00 +00:00
|
|
|
if err != nil {
|
|
|
|
b.Fatal(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|