<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>

#define eprintf(format, ...) do {               \
    if (verbose)                                \
        fprintf(stdout, format, ##__VA_ARGS__); \
    else                                        \
        fprintf(stdout, ".");                   \
    fflush(stdout);                             \
} while(0)

int verbose = 1;

mapper_device source = 0;
mapper_device destination = 0;
mapper_signal sendsig = 0;
mapper_signal recvsig = 0;

int numTrials = 10;
int trial = 0;
int numModes = 2;
int mode = 0;
int use_instance = 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_source()
{
    source = mapper_device_new("testSpeedSend", 0, 0);
    if (!source)
        goto error;
    eprintf("source created.\n");

    sendsig = mapper_device_add_output_signal(source, "outsig", 1, 'f', 0, 0, 0);
    if (!sendsig)
        goto error;
    mapper_signal_reserve_instances(sendsig, 9, 0, 0);

    eprintf("Output signal registered.\n");
    eprintf("Number of outputs: %d\n",
            mapper_device_num_signals(source, MAPPER_DIR_OUTGOING));

    return 0;

  error:
    return 1;
}

void cleanup_source()
{
    if (source) {
        eprintf("Freeing source.. ");
        fflush(stdout);
        mapper_device_free(source);
        eprintf("ok\n");
    }
}

void insig_handler(mapper_signal sig, mapper_id instance, const void *value,
                   int count, mapper_timetag_t *timetag)
{
    if (value) {
        counter = (counter+1)%10;
        if (++received >= iterations)
            switch_modes();
        if (use_instance) {
            mapper_signal_instance_update(sendsig, counter, value, 1,
                                          MAPPER_NOW);
        }
        else
            mapper_signal_update(sendsig, value, 1, MAPPER_NOW);
    }
    else
        eprintf("--> destination %s instance %ld got NULL\n",
                sig->name, (long)instance);
}

/*! Creation of a local destination. */
int setup_destination()
{
    destination = mapper_device_new("testSpeedRecv", 0, 0);
    if (!destination)
        goto error;
    eprintf("destination created.\n");

    recvsig = mapper_device_add_input_signal(destination, "insig", 1, 'f', 0, 0,
                                             0, insig_handler, 0);
    if (!recvsig)
        goto error;
    mapper_signal_reserve_instances(recvsig, 9, 0, 0);

    eprintf("Input signal registered.\n");
    eprintf("Number of inputs: %d\n",
            mapper_device_num_signals(destination, MAPPER_DIR_INCOMING));

    return 0;

  error:
    return 1;
}<commit_msg>Fix number of allocated instances in speed test.<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>

#define eprintf(format, ...) do {               \
    if (verbose)                                \
        fprintf(stdout, format, ##__VA_ARGS__); \
    else                                        \
        fprintf(stdout, ".");                   \
    fflush(stdout);                             \
} while(0)

int verbose = 1;

mapper_device source = 0;
mapper_device destination = 0;
mapper_signal sendsig = 0;
mapper_signal recvsig = 0;

int numTrials = 10;
int trial = 0;
int numModes = 2;
int mode = 0;
int use_instance = 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_source()
{
    source = mapper_device_new("testSpeedSend", 0, 0);
    if (!source)
        goto error;
    eprintf("source created.\n");

    sendsig = mapper_device_add_output_signal(source, "outsig", 1, 'f', 0, 0, 0);
    if (!sendsig)
        goto error;
    mapper_signal_reserve_instances(sendsig, 10, 0, 0);

    eprintf("Output signal registered.\n");
    eprintf("Number of outputs: %d\n",
            mapper_device_num_signals(source, MAPPER_DIR_OUTGOING));

    return 0;

  error:
    return 1;
}

void cleanup_source()
{
    if (source) {
        eprintf("Freeing source.. ");
        fflush(stdout);
        mapper_device_free(source);
        eprintf("ok\n");
    }
}

void insig_handler(mapper_signal sig, mapper_id instance, const void *value,
                   int count, mapper_timetag_t *timetag)
{
    if (value) {
        counter = (counter+1)%10;
        if (++received >= iterations)
            switch_modes();
        if (use_instance) {
            mapper_signal_instance_update(sendsig, counter, value, 1,
                                          MAPPER_NOW);
        }
        else
            mapper_signal_update(sendsig, value, 1, MAPPER_NOW);
    }
    else
        eprintf("--> destination %s instance %ld got NULL\n",
                sig->name, (long)instance);
}

/*! Creation of a local destination. */
int setup_destination()
{
    destination = mapper_device_new("testSpeedRecv", 0, 0);
    if (!destination)
        goto error;
    eprintf("destination created.\n");

    recvsig = mapper_device_add_input_signal(destination, "insig", 1, 'f', 0, 0,
                                             0, insig_handler, 0);
    if (!recvsig)
        goto error;
    mapper_signal_reserve_instances(recvsig, 10, 0, 0);

    eprintf("Input signal registered.\n");
    eprintf("Number of inputs: %d\n",
            mapper_device_num_signals(destination, MAPPER_DIR_INCOMING));

    return 0;

  error:
    return 1;
}
{'fraction_non_alphanumeric': 0.12521821933026503, 'fraction_numerical': 0.019362006030788765, 'mean_word_length': 2.3012048192771086, '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': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1408247', 'n_tokens_mistral': 2184, 'n_tokens_neox': 2042, 'n_words': 509}