static int benchmark(const uint32_t num_iterations) { ALIGN(16) uint8_t k[KEYLEN]; ALIGN(16) uint8_t* m = (uint8_t*)malloc(MAX_BUFFER_LEN); ALIGN(16) uint8_t* c = (uint8_t*)malloc(MAX_BUFFER_LEN); ALIGN(16) uint8_t t[TAGLEN]; uint64_t mlen; const uint64_t hlen = 0L; const uint64_t calibration = calibrate_timer(); uint64_t t0, t1; uint32_t i, j; prepare_k(k, KEYLEN); prepare_m(m, MAX_BUFFER_LEN); riv_context_t ctx; keysetup(&ctx, k); puts("#mlen cpb"); double timings[num_iterations]; const uint32_t median = num_iterations / 2; // To load the timing code into the instruction cache get_time(); for (j = MIN_CONT_MSG_LEN; j < MAX_CONT_MSG_LEN; ++j) { mlen = j; t0 = get_time(); t1 = get_time(); for (i = 0; i < num_iterations; ++i) { t0 = get_time(); FN_TO_BENCH(&ctx, m, mlen, NULL, hlen, c, t); t1 = get_time(); timings[i] = (double)(t1 - t0 - calibration) / j; } // Sort the measurements and print the median qsort(timings, num_iterations, sizeof(double), compare_doubles); printf("%5d %4.3lf \n", j, timings[median]); } uint32_t interval_len; uint32_t j_outer; for (j_outer = MAX_CONT_MSG_LEN; j_outer < MAX_BUFFER_LEN; j_outer = 2*j_outer) { interval_len = j_outer / NUM_INTERVALS; for (j = j_outer; j < 2*j_outer; j += interval_len) { mlen = j; t0 = get_time(); t1 = get_time(); for (i = 0; i < num_iterations; ++i) { t0 = get_time(); FN_TO_BENCH(&ctx, m, mlen, NULL, hlen, c, t); t1 = get_time(); timings[i] = (double)(t1 - t0 - calibration) / j; } // Sort the measurements and print the median qsort(timings, num_iterations, sizeof(double), compare_doubles); printf("%5d %4.3lf \n", j, timings[median]); } } t0 = get_time(); t1 = get_time(); mlen = MAX_BUFFER_LEN; for (i = 0; i < num_iterations; ++i) { t0 = get_time(); FN_TO_BENCH(&ctx, m, mlen, NULL, hlen, c, t); t1 = get_time(); timings[i] = (double)(t1 - t0 - calibration) / mlen; } // Sort the measurements and print the median qsort(timings, num_iterations, sizeof(double), compare_doubles); printf("%5lu %4.3lf \n", mlen, timings[median]); free(c); free(m); return 0; }
void quality_benchmark_fann_som(unsigned int width, unsigned int height, char *topology, char *neighborhood, char *decay, struct fann_train_data *train_data, struct fann_train_data *test_data, FILE * train_out, unsigned int num_input, unsigned int max_training_examples, double seconds_between_reports) { float test_error; double elapsed = 0; double total_elapsed = 0; struct fann *ann; unsigned int current_example = 0; ann = fann_create_som(width, height, num_input); /* Set the topology */ if (!strcmp(topology, "hexagonal")) { ann->som_params->som_topology = FANN_SOM_TOPOLOGY_HEXAGONAL; } else if (!strcmp(topology, "rectangular")) { ann->som_params->som_topology = FANN_SOM_TOPOLOGY_RECTANGULAR; } else { fprintf(stderr, "Error: Unknown topology: %s\n", topology); exit(1); } /* Set the neighborhood */ if (!strcmp(neighborhood, "distance")) { ann->som_params->som_neighborhood = FANN_SOM_NEIGHBORHOOD_DISTANCE; } else if (!strcmp(neighborhood, "gaussian")) { ann->som_params->som_neighborhood = FANN_SOM_NEIGHBORHOOD_GAUSSIAN; } else { fprintf(stderr, "Error: Unknown neighborhood: %s\n", neighborhood); exit(1); } /* Set the decay */ if (!strcmp(decay, "linear")) { ann->som_params->som_learning_decay = FANN_SOM_LEARNING_DECAY_LINEAR; } else if (!strcmp(decay, "inverse")) { ann->som_params->som_learning_decay = FANN_SOM_LEARNING_DECAY_INVERSE; } else { fprintf(stderr, "Error: Unknown decay type: %s\n", decay); exit(1); } calibrate_timer(); while (current_example < max_training_examples) { /* train */ elapsed = 0; start_timer(); while((elapsed < (double) seconds_between_reports) && (current_example < max_training_examples)) { fann_train_example_som(ann, train_data, current_example, max_training_examples); elapsed = time_elapsed(); current_example++; } stop_timer(); total_elapsed += getSecs(); /* make report */ test_error = fann_get_MSE_som(ann, test_data); /* output the statistics */ fprintf(train_out, "%8.2f %8.6f %5d\n", total_elapsed, test_error, current_example); fprintf(stderr, "secs: %8.2f, test_error: %8.6f training_examples: %5d\r", total_elapsed, test_error, current_example); } fprintf(stdout, "\nTraining samples: %d, samples/sec: %f\n", max_training_examples, (float)max_training_examples / total_elapsed); fann_destroy(ann); }