Repository: google/benchmark
File: include/benchmark/benchmark.h (C/C++)

Code before:

  // Construct BenchmarkName with a given 'root'.
  BenchmarkName(std::string root);

  // Append 'field_content' to a given field of the name.
  // Each appended element of content for a given field will be
  // separated by a '/', and additionally each field will
  // be separated by a '/'.
  BenchmarkName& append(Field field, const std::string& field_content);

  // Get the benchmark's name including all the fields set in 'fields'
  std::string get(Field fields) const;

  // Get the full name of the benchmark including all fields.
  const std::string& str() const { return name_; }

  // Get the size of the full name of the benchmark.
  size_t size() const { return name_.size(); }

 private:
  bool is_set(Field field, std::size_t enumerator_index) const;
  size_t start_offset(std::size_t enumerator_index) const;
  size_t end_offset(std::size_t enumerator_index) const;

  static const char separator = '/';
  static const std::size_t enumerator_count = 7;
  static const std::size_t offset_count = enumerator_count - 1;

  std::string name_;
  uint16_t offsets_[offset_count];
};

// Bitwise-or of BenchmarkName::Field bitfield
BenchmarkName::Field operator|(BenchmarkName::Field lhs,
                               BenchmarkName::Field rhs);

// Bitwise-and of BenchmarkName::Field bitfield
BenchmarkName::Field operator&(BenchmarkName::Field lhs,
                               BenchmarkName::Field rhs);

// Bitwise-not of BenchmarkName::Field bitfield
BenchmarkName::Field operator~(BenchmarkName::Field bmn);

// Interface for custom benchmark result printers.
// By default, benchmark reports are printed to stdout. However an application
// can control the destination of the reports by calling
// RunSpecifiedBenchmarks and passing it a custom reporter object.
// The reporter object must implement the following interface.
class BenchmarkReporter {
 public:
  struct Context {

Review comment (suggestion):
this seems fragile. it might be worth allowing the enums to take their natural values and using `kAll` (which would have value 7) as the enumerator count. Then you'd just need to shift wherever you access the field in the implementation.

Code after:
    static const char* executable_name;
    Context();
  };

  struct Run {
    enum RunType { RT_Iteration, RT_Aggregate };

    Run()
        : run_type(RT_Iteration),
          error_occurred(false),
          iterations(1),
          time_unit(kNanosecond),
          real_accumulated_time(0),
          cpu_accumulated_time(0),
          max_heapbytes_used(0),
          complexity(oNone),
          complexity_lambda(),
          complexity_n(0),
          report_big_o(false),
          report_rms(false),
          counters(),
          has_memory_result(false),
          allocs_per_iter(0.0),
          max_bytes_used(0) {}

    std::string benchmark_name() const;
    BenchmarkName run_name;
    RunType run_type;          // is this a measurement, or an aggregate?
    std::string aggregate_name;
    std::string report_label;  // Empty if not set by benchmark.
    bool error_occurred;
    std::string error_message;

    int64_t iterations;
    TimeUnit time_unit;
    double real_accumulated_time;
    double cpu_accumulated_time;

    // Return a value representing the real time per iteration in the unit
    // specified by 'time_unit'.
    // NOTE: If 'iterations' is zero the returned value represents the
    // accumulated time.
    double GetAdjustedRealTime() const;

    // Return a value representing the cpu time per iteration in the unit
    // specified by 'time_unit'.
    // NOTE: If 'iterations' is zero the returned value represents the
    // accumulated time.
    double GetAdjustedCPUTime() const;

    // This is set to 0.0 if memory tracing is not enabled.