<commit_before>#include "../src/mapper_internal.h"
#include <mapper/mapper.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <sys/time.h>
#include <lo/lo.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>

int count = 0;

#define eprintf(format, ...) do {               \
    if (verbose)                                \
        fprintf(stdout, format, ##__VA_ARGS__); \
    else {                                      \
        if (count >= 20) {                      \
            count = 0;                          \
            fprintf(stdout, "\33[2K\r");        \
        }                                       \
        else {                                  \
            fprintf(stdout, ".");               \
            ++count;                            \
        }                                       \
    }                                           \
    fflush(stdout);                             \
} while(0)

int verbose = 1;

mpr_dev src = 0;
mpr_dev dst = 0;
mpr_sig sendsig = 0;
mpr_sig recvsig = 0;

int numTrials = 10;
int trial = 0;
int numModes = 2;
int mode = 0;
int use_inst = 1;
int iterations = 100000;
int counter = 0;
int received = 0;
int done = 0;

double times[100];
float value;

void switch_modes();
void print_results();

/*! Internal function to get the current time. */
static double current_time()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
}

/*! Creation of a local source. */
int setup_src()
{
    src = mpr_dev_new("testspeed-send", 0);
    if (!src)
        goto error;
    eprintf("source created.\n");

    sendsig = mpr_sig_new(src, MPR_DIR_OUT, "outsig", 1, MPR_FLT, NULL,
                          NULL, NULL, NULL, NULL, 0);
    if (!sendsig)
        goto error;
    mpr_sig_reserve_inst(sendsig, 10, 0, 0);

    eprintf("Output signal registered.\n");
    mpr_list l = mpr_dev_get_sigs(src, MPR_DIR_OUT);
    eprintf("Number of outputs: %d\n", mpr_list_get_size(l));
    mpr_list_free(l);

    return 0;

  error:
    return 1;
}

void cleanup_src()
{
    if (src) {
        eprintf("Freeing source... ");
        fflush(stdout);
        mpr_dev_free(src);
        eprintf("ok\n");
    }
}

void handler(mpr_sig sig, mpr_sig_evt event, mpr_id inst, int length,
             mpr_type type, const void *value, mpr_time t)
{
    if (value) {
        counter = (counter+1)%10;
        if (++received >= iterations)
            switch_modes();
        if (use_inst)
            mpr_sig_set_value(sendsig, counter, length, type, value);
        else
            mpr_sig_set_value(sendsig, 0, length, type, value);
    }
    else {
        const char *name = mpr_obj_get_prop_as_str((mpr_obj)sig, MPR_PROP_NAME, NULL);
        eprintf("--> destination %s instance %ld got NULL\n", name, (long)inst);
    }
}

/*! Creation of a local destination. */
int setup_dst()
{
    dst = mpr_dev_new("testspeed-recv", 0);
    if (!dst)
        goto error;
    eprintf("destination created.\n");

    recvsig = mpr_sig_new(dst, MPR_DIR_IN, "insig", 1, MPR_FLT, NULL,
                          NULL, NULL, NULL, handler, MPR_SIG_UPDATE);
    if (!recvsig)
        goto error;
    mpr_sig_reserve_inst(recvsig, 10, 0, 0);

    eprintf("Input signal registered.\n");
    mpr_list l = mpr_dev_get_sigs(dst, MPR_DIR_IN);
    eprintf("Number of inputs: %d\n", mpr_list_get_size(l));
    mpr_list_free(l);

    return 0;

  error:
    return 1;<commit_msg>Speed up testspeed using mpr_dev_process_outputs().<commit_after>#include "../src/mapper_internal.h"
#include <mapper/mapper.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <sys/time.h>
#include <lo/lo.h>
#include <unistd.h>
#include <signal.h>
#include <string.h>

int count = 0;

#define eprintf(format, ...) do {               \
    if (verbose)                                \
        fprintf(stdout, format, ##__VA_ARGS__); \
    else {                                      \
        if (count >= 20) {                      \
            count = 0;                          \
            fprintf(stdout, "\33[2K\r");        \
        }                                       \
        else {                                  \
            fprintf(stdout, ".");               \
            ++count;                            \
        }                                       \
    }                                           \
    fflush(stdout);                             \
} while(0)

int verbose = 1;

mpr_dev src = 0;
mpr_dev dst = 0;
mpr_sig sendsig = 0;
mpr_sig recvsig = 0;

int numTrials = 10;
int trial = 0;
int numModes = 2;
int mode = 0;
int use_inst = 1;
int iterations = 100000;
int counter = 0;
int received = 0;
int done = 0;

double times[100];
float value;

void switch_modes();
void print_results();

/*! Internal function to get the current time. */
static double current_time()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return (double) tv.tv_sec + tv.tv_usec / 1000000.0;
}

/*! Creation of a local source. */
int setup_src()
{
    src = mpr_dev_new("testspeed-send", 0);
    if (!src)
        goto error;
    eprintf("source created.\n");

    sendsig = mpr_sig_new(src, MPR_DIR_OUT, "outsig", 1, MPR_FLT, NULL,
                          NULL, NULL, NULL, NULL, 0);
    if (!sendsig)
        goto error;
    mpr_sig_reserve_inst(sendsig, 10, 0, 0);

    eprintf("Output signal registered.\n");
    mpr_list l = mpr_dev_get_sigs(src, MPR_DIR_OUT);
    eprintf("Number of outputs: %d\n", mpr_list_get_size(l));
    mpr_list_free(l);

    return 0;

  error:
    return 1;
}

void cleanup_src()
{
    if (src) {
        eprintf("Freeing source... ");
        fflush(stdout);
        mpr_dev_free(src);
        eprintf("ok\n");
    }
}

void handler(mpr_sig sig, mpr_sig_evt event, mpr_id inst, int length,
             mpr_type type, const void *value, mpr_time t)
{
    if (value) {
        counter = (counter+1)%10;
        if (++received >= iterations)
            switch_modes();
        if (use_inst)
            mpr_sig_set_value(sendsig, counter, length, type, value);
        else
            mpr_sig_set_value(sendsig, 0, length, type, value);
        mpr_dev_process_outputs(mpr_sig_get_dev(sig));
    }
    else {
        const char *name = mpr_obj_get_prop_as_str((mpr_obj)sig, MPR_PROP_NAME, NULL);
        eprintf("--> destination %s instance %ld got NULL\n", name, (long)inst);
    }
}

/*! Creation of a local destination. */
int setup_dst()
{
    dst = mpr_dev_new("testspeed-recv", 0);
    if (!dst)
        goto error;
    eprintf("destination created.\n");

    recvsig = mpr_sig_new(dst, MPR_DIR_IN, "insig", 1, MPR_FLT, NULL,
                          NULL, NULL, NULL, handler, MPR_SIG_UPDATE);
    if (!recvsig)
        goto error;
    mpr_sig_reserve_inst(recvsig, 10, 0, 0);

    eprintf("Input signal registered.\n");
    mpr_list l = mpr_dev_get_sigs(dst, MPR_DIR_IN);
    eprintf("Number of inputs: %d\n", mpr_list_get_size(l));
    mpr_list_free(l);

    return 0;

  error:
    return 1;
{'fraction_non_alphanumeric': 0.12867802337040687, 'fraction_numerical': 0.016894270026749262, 'mean_word_length': 1.8090154211150653, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6370193', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2439, 'n_words': 576}