<commit_before>/**
 * Definition of a Timer encapsulate timing and delays.
 */
#ifndef __avc_Timer_h
#define __avc_Timer_h

#include <iostream>

#include <time.h>

namespace avc {

  /**
   * Timer class wrapper the clock_gettime function that gets a
   * monotonic time (see: "man 3 clock_gettime").
   */
  class Timer {

  public:

    /**
     * Wrapper around the nanosleep function to sleep for a precise
     * amount of time.
     *
     * @param seconds The number of seconds to sleep (you can specify
     * very small amounts of time).
     *
     * @return Will return 0.0 if the operation performed normally
     * (slept the desired time period). If the operation failed (was
     * interrupted for example), this method returns the number of
     * seconds NOT slept (still needing to sleep).
     */
    static float sleep(float seconds);

    /**
     * Used for short sleep times (less than a second).
     *
     * @param nanos How many nanoseconds to sleep in the range of [0,
     * 999,999,999].
     *
     * @return 0 If sleep successful, otherwise, the number of nanos
     * still needing to sleep.
     */
    static int sleepNanos(int nanos);
    
    /**
     * Gets a high precision time stamp that ignores real-time adjustments.
     *
     * @param storeIn Where to store the results.
     *
     * @return true If successfully got time, false if not (check
     * errno - see "man clock_gettime" for details).
     */
    static bool getTime(timespec& storeIn) {
      storeIn.tv_sec = 0;
      storeIn.tv_nsec = 0;
      return clock_gettime(CLOCK_MONOTONIC_RAW, &storeIn) == 0;
    }

    /**
     * Computes the difference between two time stamps in seconds.
     *
     * @param fromHere The starting point in time.
     * @param toHere The ending point in time.
     *
     * @returns (toHere - fromHere) as a number of seconds.
     */
    static float diffSecs(const timespec& fromHere, const timespec& toHere);

    /**
     * Indicates whether the timer is running or paused.
     */
    bool isRunning() const {
      return running;
    }

    /**
     * Resets and starts the timer (sets start time to current time
     * and puts timer in a running state).
     */
    bool start() {
      Timer::getTime(startTime);
      endTime = startTime;
      running = true;
    }

    /**
     * Pauses the timer (records the pause time and takes timer out of
     * running state).
     */
    bool pause() {
      Timer::getTime(endTime);
      running = false;
    }

    /**
     * Puts the timer back in a running state (without resetting the
     * start time).
     */
    bool unpause() {
      running = true;<commit_msg>Added methods to zero the timer and to start it in a paused state<commit_after>/**
 * Definition of a Timer encapsulate timing and delays.
 */
#ifndef __avc_Timer_h
#define __avc_Timer_h

#include <iostream>

#include <time.h>

namespace avc {

  /**
   * Timer class wrapper the clock_gettime function that gets a
   * monotonic time (see: "man 3 clock_gettime").
   */
  class Timer {

  public:

    /**
     * Wrapper around the nanosleep function to sleep for a precise
     * amount of time.
     *
     * @param seconds The number of seconds to sleep (you can specify
     * very small amounts of time).
     *
     * @return Will return 0.0 if the operation performed normally
     * (slept the desired time period). If the operation failed (was
     * interrupted for example), this method returns the number of
     * seconds NOT slept (still needing to sleep).
     */
    static float sleep(float seconds);

    /**
     * Used for short sleep times (less than a second).
     *
     * @param nanos How many nanoseconds to sleep in the range of [0,
     * 999,999,999].
     *
     * @return 0 If sleep successful, otherwise, the number of nanos
     * still needing to sleep.
     */
    static int sleepNanos(int nanos);
    
    /**
     * Gets a high precision time stamp that ignores real-time adjustments.
     *
     * @param storeIn Where to store the results.
     *
     * @return true If successfully got time, false if not (check
     * errno - see "man clock_gettime" for details).
     */
    static bool getTime(timespec& storeIn) {
      storeIn.tv_sec = 0;
      storeIn.tv_nsec = 0;
      return clock_gettime(CLOCK_MONOTONIC_RAW, &storeIn) == 0;
    }

    /**
     * Computes the difference between two time stamps in seconds.
     *
     * @param fromHere The starting point in time.
     * @param toHere The ending point in time.
     *
     * @returns (toHere - fromHere) as a number of seconds.
     */
    static float diffSecs(const timespec& fromHere, const timespec& toHere);

    /**
     * Indicates whether the timer is running or paused.
     */
    bool isRunning() const {
      return running;
    }

    /**
     * Resets and starts the timer (sets start time to current time
     * and puts timer in a running state).
     */
    bool start() {
      Timer::getTime(startTime);
      endTime = startTime;
      running = true;
    }

    /**
     * Resets and starts the timer, but in a paused state (elapsed
     * time will return 0.0 until you unpause it).
     */
    bool startPaused() {
      Timer::getTime(startTime);
      endTime = startTime;
      running = false;
    }

    /**
     * Pauses the timer (records the pause time and takes timer out of
     * running state).
     */
    bool pause() {
      Timer::getTime(endTime);
      running = false;
    }

    /**
     * Puts the timer back in a running state (without resetting the
     * start time).
     */
    bool unpause() {
      running = true;
    }

    /**
     * Sets timer to a paused state and moves end time to start time
     * so elapsed time will come back as 0.
     */
    bool zero() {
      endTime = startTime;
      running = false;
{'fraction_non_alphanumeric': 0.0881698339325458, 'fraction_numerical': 0.0063345317582605715, 'mean_word_length': 2.2134213421342133, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5846293', 'n_tokens_mistral': 1750, 'n_tokens_neox': 1663, 'n_words': 671}