prysm-pulse/beacon-chain/sync/initial-sync/fsm_benchmark_test.go
Victor Farazdagi d79950ab3b
Optimizes FSM event triggering (#5881)
* Optimizes machine triggering
* updates queue
* Merge branch 'master' into init-sync-fsm-optimizations
* gazelle
* Merge branch 'init-sync-fsm-optimizations' of github.com:prysmaticlabs/prysm into init-sync-fsm-optimizations
2020-05-16 20:26:00 +00:00

48 lines
1.0 KiB
Go

package initialsync
import (
"testing"
)
func BenchmarkStateMachine_trigger(b *testing.B) {
sm := newStateMachine()
handlerFn := func(state *epochState, in interface{}) (id stateID, err error) {
response, ok := in.(*fetchRequestParams)
if !ok {
return 0, errInputNotFetchRequestParams
}
_ = response.count
return stateScheduled, nil
}
sm.addHandler(stateNew, eventSchedule, handlerFn)
sm.addHandler(stateScheduled, eventDataReceived, handlerFn)
sm.addHandler(stateDataParsed, eventReadyToSend, handlerFn)
sm.addHandler(stateSkipped, eventExtendWindow, handlerFn)
sm.addHandler(stateSent, eventCheckStale, handlerFn)
for i := uint64(0); i < lookaheadEpochs; i++ {
sm.addEpochState(i)
}
b.ReportAllocs()
b.ResetTimer()
event, ok := sm.events[eventSchedule]
if !ok {
b.Errorf("event not found: %v", eventSchedule)
}
for i := 0; i < b.N; i++ {
data := &fetchRequestParams{
start: 23,
count: 32,
}
err := sm.epochs[1].trigger(event, data)
if err != nil {
b.Fatal(err)
}
}
}