MozGTestBench.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2. * This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "MozGTestBench.h"
  6. #include "mozilla/TimeStamp.h"
  7. #include <stdio.h>
  8. #define MOZ_GTEST_BENCH_FRAMEWORK "platform_microbench"
  9. using mozilla::TimeStamp;
  10. namespace mozilla {
  11. void GTestBench(const char* aSuite, const char* aName,
  12. const mozilla::function<void()>& aTest)
  13. {
  14. #ifdef DEBUG
  15. // Run the test to make sure that it doesn't fail but don't log
  16. // any measurements since it's not an optimized build.
  17. aTest();
  18. #else
  19. mozilla::TimeStamp start = TimeStamp::Now();
  20. aTest();
  21. int msDuration = (TimeStamp::Now() - start).ToMicroseconds();
  22. // Print the result for each test. Let perfherder aggregate for us
  23. printf("PERFHERDER_DATA: {\"framework\": {\"name\": \"%s\"}, "
  24. "\"suites\": [{\"name\": \"%s\", \"subtests\": "
  25. "[{\"name\": \"%s\", \"value\": %i, \"lowerIsBetter\": true}]"
  26. "}]}\n",
  27. MOZ_GTEST_BENCH_FRAMEWORK, aSuite, aName, msDuration);
  28. #endif
  29. }
  30. } // mozilla