<commit_before>#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "config.h"
#include "image.h"
#include "homomorf.h"

typedef struct _Options {
    char *conf_file;
    int no_gui;
    int time;
} Options;


int run(const Config *config, const Options *options) {
    Image *input = read_image(config->input_filename, config);

    if(!input) {
        printf("ERROR: Couldn't load input file %s.\n", config->input_filename);
        return EXIT_FAILURE;
    }

    size_t offset = 0;
    size_t width = input->cols + 20; // NOTE 20 px margin

    if(!options->no_gui) {
        printf("GUI mode, press any key to exit.\n");

        show_image(config->title_input, 100 + width * offset, 100, input);
        ++offset;
    }

    Image *SNR = read_image(config->input_filename_SNR, config);

    if(!SNR) {
        printf("Not using an SNR map.\n");
    }

    Image *rician = NULL, *gaussian = NULL;

    double t_min = 1e30;
    double t_max = 0.0;
    double t_total = 0.0;

    clock_t diff, start;
    size_t num_times = options->time ? options->time : 1;
    int ret = -1;

    if(options->time) {
        printf("Running %ld tests:\n", num_times);
    }

    for(size_t i = 0; i < num_times; ++i) {
        start= clock();
        ret = homomorf_est(input, &SNR, &rician, &gaussian, config);
        diff = clock() - start;
        double ms = diff * 1000.0 / CLOCKS_PER_SEC;

        t_total += ms;
        t_max = ms > t_max ? ms : t_max;
        t_min = ms < t_min ? ms : t_min;
    }<commit_msg>Fix timing code to reset the SNR map.<commit_after>#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "config.h"
#include "image.h"
#include "homomorf.h"

typedef struct _Options {
    char *conf_file;
    int no_gui;
    int time;
} Options;


int run(const Config *config, const Options *options) {
    Image *input = read_image(config->input_filename, config);

    if(!input) {
        printf("ERROR: Couldn't load input file %s.\n", config->input_filename);
        return EXIT_FAILURE;
    }

    size_t offset = 0;
    size_t width = input->cols + 20; // NOTE 20 px margin

    if(!options->no_gui) {
        printf("GUI mode, press any key to exit.\n");

        show_image(config->title_input, 100 + width * offset, 100, input);
        ++offset;
    }

    Image *SNR = read_image(config->input_filename_SNR, config);
    int delete_SNR = 0;

    if(SNR == NULL) {
        printf("Not using an SNR map.\n");
        delete_SNR = options->time;
    }

    Image *rician = NULL, *gaussian = NULL;

    double t_min = 1e30;
    double t_max = 0.0;
    double t_total = 0.0;

    clock_t diff, start;
    size_t num_times = options->time ? options->time : 1;
    int ret = -1;

    if(options->time) {
        printf("Running %ld tests:\n", num_times);
    }

    for(size_t i = 0; i < num_times; ++i) {
        if(rician != NULL) {
            cvReleaseMat(&rician);
            cvReleaseMat(&gaussian);
        }

        if(delete_SNR && SNR != NULL) {
            cvReleaseMat(&SNR);
        }

        start= clock();
        ret = homomorf_est(input, &SNR, &rician, &gaussian, config);
        diff = clock() - start;
        double ms = diff * 1000.0 / CLOCKS_PER_SEC;

        t_total += ms;
        t_max = ms > t_max ? ms : t_max;
        t_min = ms < t_min ? ms : t_min;
    }
{'fraction_non_alphanumeric': 0.13865546218487396, 'fraction_numerical': 0.015906362545018007, 'mean_word_length': 2.3263473053892216, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 30, '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': '2671219', 'n_tokens_mistral': 1235, 'n_tokens_neox': 1152, 'n_words': 307}