<commit_before>#ifndef __LIQUID_FEC_BENCHMARK_H__
#define __LIQUID_FEC_BENCHMARK_H__

#include <sys/resource.h>
#include "../src/fec.h"

#define BSIZE   64

//
// BENCHMARK: Repeat/3 codec
//
void benchmark_rep3_encode(
    struct rusage *_start,
    struct rusage *_finish,
    unsigned long int *_num_iterations)
{
    unsigned long int i;
    unsigned int n=BSIZE;
    unsigned char msg_dec[n], msg_enc[3*n];

    getrusage(RUSAGE_SELF, _start);
    for (i=0; i<(*_num_iterations); i++) {
        fec_rep3_encode(msg_dec, n, msg_enc);
        fec_rep3_encode(msg_dec, n, msg_enc);
        fec_rep3_encode(msg_dec, n, msg_enc);
        fec_rep3_encode(msg_dec, n, msg_enc);
    }
    getrusage(RUSAGE_SELF, _finish);

    *_num_iterations *= 4;
}

void benchmark_rep3_decode(
    struct rusage *_start,
    struct rusage *_finish,
    unsigned long int *_num_iterations)
{
    unsigned long int i;
    unsigned int n=BSIZE;
    unsigned char msg_dec[n], msg_enc[3*n];

    getrusage(RUSAGE_SELF, _start);
    for (i=0; i<(*_num_iterations); i++) {
        fec_rep3_decode(msg_enc, n, msg_dec);
        fec_rep3_decode(msg_enc, n, msg_dec);
        fec_rep3_decode(msg_enc, n, msg_dec);
        fec_rep3_decode(msg_enc, n, msg_dec);
    }
    getrusage(RUSAGE_SELF, _finish);

    *_num_iterations *= 4;
}

//
// BENCHMARK: Hamming (7,4) codec
//
void benchmark_hamming74_encode(
    struct rusage *_start,
    struct rusage *_finish,
    unsigned long int *_num_iterations)
{
    unsigned long int i;
    unsigned int n=BSIZE;
    unsigned char msg_dec[n], msg_enc[2*n];

    getrusage(RUSAGE_SELF, _start);
    for (i=0; i<(*_num_iterations); i++) {
        fec_hamming74_encode(msg_dec, n, msg_enc);
        fec_hamming74_encode(msg_dec, n, msg_enc);
        fec_hamming74_encode(msg_dec, n, msg_enc);
        fec_hamming74_encode(msg_dec, n, msg_enc);
    }
    getrusage(RUSAGE_SELF, _finish);

    *_num_iterations *= 4;
}

void benchmark_hamming74_decode(
    struct rusage *_start,
    struct rusage *_finish,
    unsigned long int *_num_iterations)
{
    unsigned long int i;
    unsigned int n=BSIZE;
    unsigned char msg_dec[n], msg_enc[2*n];

    getrusage(RUSAGE_SELF, _start);
    for (i=0; i<(*_num_iterations); i++) {
        fec_hamming74_decode(msg_enc, n, msg_dec);
        fec_hamming74_decode(msg_enc, n, msg_dec);
        fec_hamming74_decode(msg_enc, n, msg_dec);
        fec_hamming74_decode(msg_enc, n, msg_dec);
    }
    getrusage(RUSAGE_SELF, _finish);

    *_num_iterations *= 4;
}

#endif // __LIQUID_FEC_BENCHMARK_H__
<commit_msg>fec/benchmark: adding more benchmarks; new api<commit_after>#ifndef __LIQUID_FEC_BENCHMARK_H__
#define __LIQUID_FEC_BENCHMARK_H__

#include <sys/resource.h>
#include <stdlib.h>

#include "../src/fec.h"

#define BSIZE   64

#define FEC_ENCODE_BENCH_API(FS,N, OPT) \
(   struct rusage *_start,              \
    struct rusage *_finish,             \
    unsigned long int *_num_iterations) \
{ fec_encode_bench(_start, _finish, _num_iterations, FS, N, OPT); }

// Helper function to keep code base small
void fec_encode_bench(
    struct rusage *_start,
    struct rusage *_finish,
    unsigned long int *_num_iterations,
    fec_scheme _fs,
    unsigned int _n,
    void * _opts)
{
    // generate fec object
    fec q = fec_create(_fs,_n,_opts);

    // create arrays
    unsigned int n_enc = fec_get_enc_msg_length(_fs,_n);
    unsigned char msg[_n];          // original message
    unsigned char msg_enc[n_enc];   // encoded message

    // initialze message
    unsigned long int i;
    for (i=0; i<_n; i++) {
        msg[i] = rand() & 0xff;
    }

    // start trials
    getrusage(RUSAGE_SELF, _start);
    for (i=0; i<(*_num_iterations); i++) {
        fec_encode(q,msg,msg_enc);
        fec_encode(q,msg,msg_enc);
        fec_encode(q,msg,msg_enc);
        fec_encode(q,msg,msg_enc);
    }
    getrusage(RUSAGE_SELF, _finish);
    *_num_iterations *= 4;

    // clean up objects
    fec_destroy(q);
}

//
// BENCHMARKS
//
void benchmark_fec_rep3_n4          FEC_ENCODE_BENCH_API(FEC_REP3, 4,   NULL)
void benchmark_fec_rep3_n16         FEC_ENCODE_BENCH_API(FEC_REP3, 16,  NULL)
void benchmark_fec_rep3_n64         FEC_ENCODE_BENCH_API(FEC_REP3, 64,  NULL)
void benchmark_fec_rep3_n256        FEC_ENCODE_BENCH_API(FEC_REP3, 256, NULL)

void benchmark_fec_hamming74_n4     FEC_ENCODE_BENCH_API(FEC_HAMMING74, 4,   NULL)
void benchmark_fec_hamming74_n16    FEC_ENCODE_BENCH_API(FEC_HAMMING74, 16,  NULL)
void benchmark_fec_hamming74_n64    FEC_ENCODE_BENCH_API(FEC_HAMMING74, 64,  NULL)
void benchmark_fec_hamming74_n256   FEC_ENCODE_BENCH_API(FEC_HAMMING74, 256, NULL)

#endif // __LIQUID_FEC_BENCHMARK_H__

{'fraction_non_alphanumeric': 0.10711994868505452, 'fraction_numerical': 0.023305537737866155, 'mean_word_length': 3.463740458015267, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 6, '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': '2620388', 'n_tokens_mistral': 1982, 'n_tokens_neox': 1882, 'n_words': 361}