measure_node.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package leafnodes
  2. import (
  3. "reflect"
  4. "github.com/onsi/ginkgo/internal/failer"
  5. "github.com/onsi/ginkgo/types"
  6. )
  7. type MeasureNode struct {
  8. runner *runner
  9. text string
  10. flag types.FlagType
  11. samples int
  12. benchmarker *benchmarker
  13. }
  14. func NewMeasureNode(text string, body interface{}, flag types.FlagType, codeLocation types.CodeLocation, samples int, failer *failer.Failer, componentIndex int) *MeasureNode {
  15. benchmarker := newBenchmarker()
  16. wrappedBody := func() {
  17. reflect.ValueOf(body).Call([]reflect.Value{reflect.ValueOf(benchmarker)})
  18. }
  19. return &MeasureNode{
  20. runner: newRunner(wrappedBody, codeLocation, 0, failer, types.SpecComponentTypeMeasure, componentIndex),
  21. text: text,
  22. flag: flag,
  23. samples: samples,
  24. benchmarker: benchmarker,
  25. }
  26. }
  27. func (node *MeasureNode) Run() (outcome types.SpecState, failure types.SpecFailure) {
  28. return node.runner.run()
  29. }
  30. func (node *MeasureNode) MeasurementsReport() map[string]*types.SpecMeasurement {
  31. return node.benchmarker.measurementsReport()
  32. }
  33. func (node *MeasureNode) Type() types.SpecComponentType {
  34. return types.SpecComponentTypeMeasure
  35. }
  36. func (node *MeasureNode) Text() string {
  37. return node.text
  38. }
  39. func (node *MeasureNode) Flag() types.FlagType {
  40. return node.flag
  41. }
  42. func (node *MeasureNode) CodeLocation() types.CodeLocation {
  43. return node.runner.codeLocation
  44. }
  45. func (node *MeasureNode) Samples() int {
  46. return node.samples
  47. }