<commit_before>// ========================================================================== //
//
// Copyright (C) 2013 <NAME> <<EMAIL>>
// Copyright (C) 2014 <NAME>
//
// Adapted from DO++, a basic set of libraries in C++ for computer
// vision.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
// ========================================================================== //

#include <openMVG/system/timer.hpp>
#ifdef _WIN32
# include <windows.h>
#else
# include <sys/time.h>
#endif

namespace openMVG {
namespace system {

  Timer::Timer()
   {
#ifdef HAVE_CXX11_CHRONO
#else
#ifdef _WIN32
    LARGE_INTEGER freq;
    if (!QueryPerformanceFrequency(&freq))
    {
      const char *msg = "Failed to initialize high resolution timer!";
      std::cerr << msg << std::endl;
      throw std::runtime_error(msg);
    }
    frequency_ = static_cast<double>(freq.QuadPart);
#endif
#endif
    reset();
  }

  void Timer::reset()
  {
#ifdef HAVE_CXX11_CHRONO
    start_ = std::chrono::high_resolution_clock::now();
#else

#ifdef _WIN32
    LARGE_INTEGER li_start_;
    QueryPerformanceCounter(&li_start_);
    start_ = static_cast<double>(li_start_.QuadPart);
#else
    timeval start;
    gettimeofday(&start, nullptr);
    start_ = start.tv_sec + start.tv_usec * 1e-6;
#endif

#endif // HAVE_CXX11_CHRONO
  }

  double Timer::elapsed() const
  {
#ifdef HAVE_CXX11_CHRONO
  return elapsedMs() / 1000.;
#else

  double elapsed_;
#ifdef _WIN32
  LARGE_INTEGER end_;
  QueryPerformanceCounter(&end_);
  elapsed_ = (static_cast<double>(end_.QuadPart) - start_) / frequency_;
#else
  timeval end;
  gettimeofday(&end, nullptr);
  const double end_ = end.tv_sec + end.tv_usec * 1e-6;
  elapsed_ = end_ - start_;
#endif
  return elapsed_;
#endif // HAVE_CXX11_CHRONO
  }

  double Timer::elapsedMs() const
  {
#ifdef HAVE_CXX11_CHRONO
    const auto end_ = std::chrono::high_resolution_clock::now();
    return std::chrono::duration_cast<std::chrono::milliseconds>(end_ - start_).count();
#else
    return elapsed() * 1000.;
#endif // HAVE_CXX11_CHRONO
  }

  std::ostream& operator << (std::ostream& str, const Timer& t)
  {
    return str << t.elapsed() << " s elapsed";
  }

} // namespace system
} // namespace openMVG<commit_msg>[system] formatting<commit_after>// ========================================================================== //
//
// Copyright (C) 2013 <NAME> <<EMAIL>>
// Copyright (C) 2014 <NAME>
//
// Adapted from DO++, a basic set of libraries in C++ for computer
// vision.
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License v. 2.0. If a copy of the MPL was not distributed with this file,
// you can obtain one at http://mozilla.org/MPL/2.0/.
// ========================================================================== //

#include <openMVG/system/timer.hpp>
#ifdef _WIN32
# include <windows.h>
#else
# include <sys/time.h>
#endif

namespace openMVG {
namespace system {

Timer::Timer()
{
#ifndef HAVE_CXX11_CHRONO
#ifdef _WIN32
  LARGE_INTEGER freq;
  if (!QueryPerformanceFrequency(&freq))
  {
    const char *msg = "Failed to initialize high resolution timer!";
    std::cerr << msg << std::endl;
    throw std::runtime_error(msg);
  }
  frequency_ = static_cast<double>(freq.QuadPart);
#endif
#endif
  reset();
}

void Timer::reset()
{
#ifdef HAVE_CXX11_CHRONO
  start_ = std::chrono::high_resolution_clock::now();
#else

#ifdef _WIN32
  LARGE_INTEGER li_start_;
  QueryPerformanceCounter(&li_start_);
  start_ = static_cast<double>(li_start_.QuadPart);
#else
  timeval start;
  gettimeofday(&start, nullptr);
  start_ = start.tv_sec + start.tv_usec * 1e-6;
#endif

#endif // HAVE_CXX11_CHRONO
}

double Timer::elapsed() const
{
#ifdef HAVE_CXX11_CHRONO
  return elapsedMs() / 1000.;
#else

  double elapsed_;
#ifdef _WIN32
  LARGE_INTEGER end_;
  QueryPerformanceCounter(&end_);
  elapsed_ = (static_cast<double>(end_.QuadPart) - start_) / frequency_;
#else
  timeval end;
  gettimeofday(&end, nullptr);
  const double end_ = end.tv_sec + end.tv_usec * 1e-6;
  elapsed_ = end_ - start_;
#endif
  return elapsed_;
#endif // HAVE_CXX11_CHRONO
}

double Timer::elapsedMs() const
{
#ifdef HAVE_CXX11_CHRONO
  const auto end_ = std::chrono::high_resolution_clock::now();
  return std::chrono::duration_cast<std::chrono::milliseconds>(end_ - start_).count();
#else
  return elapsed() * 1000.;
#endif // HAVE_CXX11_CHRONO
}

std::ostream& operator << (std::ostream& str, const Timer& t)
{
  return str << t.elapsed() << " s elapsed";
}


  std::ostream& operator << (std::ostream& str, const Timer& t)
  {
    return str << t.elapsed() << " s elapsed";
  }

} // namespace system
} // namespace openMVG
{'fraction_non_alphanumeric': 0.1945080091533181, 'fraction_numerical': 0.019138755980861243, 'mean_word_length': 4.186623516720604, 'pattern_counts': {'":': 0, '<': 51, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4526576', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1588, 'n_words': 409}