<commit_before>/*
 * Test harness for the k-mismatches algorithms.
 */

#define _GNU_SOURCE
#include <getopt.h>
#include <sched.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/times.h>
#include <unistd.h>

/* Implemented by the test algorithms */
extern void prep(unsigned char *P, size_t m, size_t k);
extern size_t exec(unsigned char *T, size_t n, size_t k);

/*
 * Benchmarking functions.
 * <NAME>owards faster string matching. PhD thesis, 2014.
 */
static struct tms start;
void startclock()
{
    int onln;  /* number of processors online */
    if ((onln = sysconf(_SC_NPROCESSORS_ONLN)) > 1) {
        int i;
        pid_t pid = getpid();
        cpu_set_t cpu_set;
        CPU_ZERO(&cpu_set);
        CPU_SET(onln-1, &cpu_set);  /* CPU numbering starts from 0 */
        if (sched_setaffinity(pid, sizeof(cpu_set), &cpu_set) != 0) {
            printf("Setting CPU affinity failed.\n");
            abort();
        }

        if (sched_getaffinity(pid, sizeof(cpu_set), &cpu_set) != 0) {
            printf("Getting CPU affinity failed.\n");
            abort();
        }
        for (i = onln-2; i >= 0; i--) {
            if (CPU_ISSET(i, &cpu_set)) {
                printf("Failed to unset cpu affinity for cpu %d\n", i);
            }
        }
        if (!CPU_ISSET(onln-1, &cpu_set)) {
            printf("Failed to set cpu affinity for cpu %d\n", onln-1);
        }
    }
    times(&start);
}

clock_t stopclock()
{
    struct tms t;
    times(&t);
    return t.tms_utime - start.tms_utime;
    /* we should also keep watch on tms_stime */ 
}

/*
 * Read the contents of the stream `in' and store the content length to *size.
 * The function supports non-seekable streams such as stdin.
 *<commit_msg>fix cygwin compilation<commit_after>/*
 * Test harness for the k-mismatches algorithms.
 */

#ifdef __linux
#define _GNU_SOURCE
#include <sched.h>
#endif

#include <ctype.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/times.h>
#include <unistd.h>

/* Implemented by the test algorithms */
extern void prep(unsigned char *P, size_t m, size_t k);
extern size_t exec(unsigned char *T, size_t n, size_t k);

/*
 * Benchmarking functions.
 * <NAME>ards faster string matching. PhD thesis, 2014.
 */
static struct tms start;
void startclock()
{
#ifdef __linux
    int onln;  /* number of processors online */
    if ((onln = sysconf(_SC_NPROCESSORS_ONLN)) > 1) {
        int i;
        pid_t pid = getpid();
        cpu_set_t cpu_set;
        CPU_ZERO(&cpu_set);
        CPU_SET(onln-1, &cpu_set);  /* CPU numbering starts from 0 */
        if (sched_setaffinity(pid, sizeof(cpu_set), &cpu_set) != 0) {
            printf("Setting CPU affinity failed.\n");
            abort();
        }

        if (sched_getaffinity(pid, sizeof(cpu_set), &cpu_set) != 0) {
            printf("Getting CPU affinity failed.\n");
            abort();
        }
        for (i = onln-2; i >= 0; i--) {
            if (CPU_ISSET(i, &cpu_set)) {
                printf("Failed to unset cpu affinity for cpu %d\n", i);
            }
        }
        if (!CPU_ISSET(onln-1, &cpu_set)) {
            printf("Failed to set cpu affinity for cpu %d\n", onln-1);
        }
    }
#endif
    times(&start);
}

clock_t stopclock()
{
    struct tms t;
    times(&t);
    return t.tms_utime - start.tms_utime;
    /* we should also keep watch on tms_stime */ 
}

/*
 * Read the contents of the stream `in' and store the content length to *size.
 * The function supports non-seekable streams such as stdin.
 *
{'fraction_non_alphanumeric': 0.13204873901955227, 'fraction_numerical': 0.007367526211391329, 'mean_word_length': 2.4172313649564376, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 22, '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': '6102690', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1196, 'n_words': 356}