Added macros for profiling functions and made it possible to compile the
profiling code out
This commit is contained in:
@@ -14,20 +14,22 @@
|
||||
#include <string.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
profile_start();
|
||||
PROFILE_START;
|
||||
|
||||
profiler_sample_t cli_parse = sample_start("CLI PARSING");
|
||||
SAMPLE_START(cli_parse, "CLI PARSING");
|
||||
ProcessorArgs args = parse_args(argc, argv);
|
||||
sample_end(&cli_parse);
|
||||
SAMPLE_END(cli_parse);
|
||||
|
||||
profiler_sample_t json_parse = sample_start("JSON PARSING");
|
||||
SAMPLE_START(json_parse, "JSON PARSING");
|
||||
|
||||
jentity_t *root = load_json(args.filepath);
|
||||
|
||||
assert(root->type == JENTITY_SINGLE && root->value.type == JVAL_COLLECTION);
|
||||
sample_end(&json_parse);
|
||||
|
||||
profiler_sample_t load_pairs_json = sample_start("LOAD JSON PAIRS");
|
||||
SAMPLE_END(json_parse);
|
||||
|
||||
SAMPLE_START(load_pairs_json, "LOAD JSON PAIRS");
|
||||
|
||||
jentity_t *pairs = root->value.collection->begin;
|
||||
|
||||
assert(pairs->type == JENTITY_PAIR &&
|
||||
@@ -59,9 +61,9 @@ int main(int argc, char *argv[]) {
|
||||
point_pairs[index++] = p;
|
||||
}
|
||||
|
||||
sample_end(&load_pairs_json);
|
||||
SAMPLE_END(load_pairs_json);
|
||||
|
||||
profiler_sample_t binary_file_read = sample_start("BINARY READ");
|
||||
SAMPLE_START(binary_file_read, "BINARY READ");
|
||||
|
||||
const char *filename = "count_and_distances";
|
||||
|
||||
@@ -73,9 +75,9 @@ int main(int argc, char *argv[]) {
|
||||
fseek(fp, sizeof(u64), SEEK_SET);
|
||||
}
|
||||
|
||||
sample_end(&binary_file_read);
|
||||
SAMPLE_END(binary_file_read);
|
||||
|
||||
profiler_sample_t haversine_sum = sample_start("HAVERSINE SUM");
|
||||
SAMPLE_START(haversine_sum, "HAVERSINE SUM");
|
||||
|
||||
f64 sum = 0.0;
|
||||
f64 distance = 0.0;
|
||||
@@ -95,13 +97,13 @@ int main(int argc, char *argv[]) {
|
||||
sum += distance;
|
||||
}
|
||||
|
||||
sample_end(&haversine_sum);
|
||||
SAMPLE_END(haversine_sum);
|
||||
|
||||
profiler_sample_t haversine_average = sample_start("HAVERSINE AVERAGE");
|
||||
SAMPLE_START(haversine_average, "HAVERSINE AVERAGE");
|
||||
printf("\nAVERAGE DISTANCE: %f\n", sum / pair_count);
|
||||
sample_end(&haversine_average);
|
||||
SAMPLE_END(haversine_average);
|
||||
|
||||
profiler_sample_t tear_down = sample_start("TEAR DOWN");
|
||||
SAMPLE_START(tear_down, "TEAR DOWN");
|
||||
|
||||
if (fp) {
|
||||
fclose(fp);
|
||||
@@ -109,9 +111,9 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
free(point_pairs);
|
||||
|
||||
sample_end(&tear_down);
|
||||
SAMPLE_END(tear_down);
|
||||
|
||||
profile_end();
|
||||
PROFILE_END;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -6,8 +6,6 @@
|
||||
|
||||
#include <x86intrin.h>
|
||||
|
||||
#define MAX_PROFILE_SAMPLES 1024
|
||||
|
||||
typedef struct {
|
||||
profiler_sample_t samples[MAX_PROFILE_SAMPLES];
|
||||
u64 cpu_freq;
|
||||
|
||||
Reference in New Issue
Block a user