<commit_before>/*
 * Copyright 2014-2019 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NANOMARK_H
#define NANOMARK_H

#include <iostream>
#include <vector>
#include <thread>
#include <atomic>

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#if defined(__linux__) || defined(Darwin)
#   include <time.h>
#elif defined(WIN32)
#   include <windows.h>
#else
#   error "Must define Darwin or __linux__ or WIN32"
#endif

#define DEFAULT_REPETITIONS (1)
#define DEFAULT_RUN_LENGTH_NS (1000 * 1000 * 1000L)

extern "C"
{
#include "hdr_histogram.h"
}

namespace nanomark
{

#if defined(__linux__) || defined(Darwin)

static std::uint64_t nanoClock()
{
    struct timespec ts = {0, 0};

    clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
    return (ts.tv_sec * 1000000000) + ts.tv_nsec;
}

#elif defined(WIN32)

static std::uint64_t nanoClock()
{
    static LARGE_INTEGER freq;
    static bool first = true;
    LARGE_INTEGER counter;

    if (first)
    {
        ::QueryPerformanceFrequency(&freq);
        first = false;
    }

    ::QueryPerformanceCounter(&counter);

    return (1000000000 * counter.QuadPart)/freq.QuadPart;
}

#endif

class Nanomark
{
public:
    virtual void setUp()
    {<commit_msg>[C++]: change default clock for Linux to be CLOCK_MONOTONIC.<commit_after>/*
 * Copyright 2014-2019 Real Logic Ltd.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef NANOMARK_H
#define NANOMARK_H

#include <iostream>
#include <vector>
#include <thread>
#include <atomic>

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <string.h>

#if defined(__linux__) || defined(Darwin)
#   include <time.h>
#elif defined(WIN32)
#   include <windows.h>
#else
#   error "Must define Darwin or __linux__ or WIN32"
#endif

#define DEFAULT_REPETITIONS (1)
#define DEFAULT_RUN_LENGTH_NS (1000 * 1000 * 1000L)

extern "C"
{
#include "hdr_histogram.h"
}

namespace nanomark
{

#if defined(Darwin)

static std::uint64_t nanoClock()
{
    struct timespec ts = {0, 0};

    clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
    return (ts.tv_sec * 1000000000) + ts.tv_nsec;
}

#elif defined(__linux__)

static std::uint64_t nanoClock()
{
    struct timespec ts = {0, 0};

    clock_gettime(CLOCK_MONOTONIC, &ts);
    return (ts.tv_sec * 1000000000) + ts.tv_nsec;
}

#elif defined(WIN32)

static std::uint64_t nanoClock()
{
    static LARGE_INTEGER freq;
    static bool first = true;
    LARGE_INTEGER counter;

    if (first)
    {
        ::QueryPerformanceFrequency(&freq);
        first = false;
    }

    ::QueryPerformanceCounter(&counter);

    return (1000000000 * counter.QuadPart)/freq.QuadPart;
}

#endif

class Nanomark
{
public:
    virtual void setUp()
    {
{'fraction_non_alphanumeric': 0.10903260288615714, 'fraction_numerical': 0.034206306787814, 'mean_word_length': 3.9641909814323606, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 5, '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': '2324443', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1225, 'n_words': 391}