ah so that's what various docs meant by serialization, as far as those examples of outside factors I guess that would certainly be true for real world code but for this test scenario I can't see them as being likely to get involved since I have 12GB RAM and a quadcore AMD64 CPU, with that combination combined with the smallness of the test app it is not a concern, I will consider them once I start using the functions to test other more serious stuff (such as define read/writes or expression handling). Also thanks for clearing up my understanding of cpuid and mfence
Edit 1: After correcting some faults in my code I noticed (like using local init variable instead of ctx->init) and adding a cpuid instruction before the rdtscp instruction as was suggested I re-ran the test and got some easier to read results, calling a function still turned out to be faster than using the if statement so I think from now on I will design my code around that concept instead
Code:
make run (in directory: /media/lee/ZXUIJI_1TB/github/mc)
cc -D OUT=main.elf -o main.elf main.c
./main.elf
Timed Action for 'if':init = 00000005663080468322, stop = 00000005663080468852, diff = 00000000000000000530, tick = 00000000000000000795
Timed Action for '{}':init = 00000005663080900284, stop = 00000005663080900841, diff = 00000000000000000557, tick = 00000000000000000909
Timed Action for '[]':init = 00000005663080912185, stop = 00000005663080912683, diff = 00000000000000000498, tick = 00000000000000000911
Timed Action for '()':init = 00000005663080921469, stop = 00000005663080921992, diff = 00000000000000000523, tick = 00000000000000000914
Timed Action for '()':init = 00000005663080931107, stop = 00000005663080931592, diff = 00000000000000000485, tick = 00000000000000000917
Timed Action for '()':init = 00000005663080939768, stop = 00000005663080940253, diff = 00000000000000000485, tick = 00000000000000000919
Timed Action for '()':init = 00000005663080947959, stop = 00000005663080948444, diff = 00000000000000000485, tick = 00000000000000000921
Timed Action for '()':init = 00000005663080956129, stop = 00000005663080956614, diff = 00000000000000000485, tick = 00000000000000000924
Timed Action for '()':init = 00000005663080964265, stop = 00000005663080964750, diff = 00000000000000000485, tick = 00000000000000000926
Timed Action for '()':init = 00000005663080972409, stop = 00000005663080972894, diff = 00000000000000000485, tick = 00000000000000000928
Timed Action for '()':init = 00000005663080981168, stop = 00000005663080981653, diff = 00000000000000000485, tick = 00000000000000000930
Timed Action for '()':init = 00000005663080989384, stop = 00000005663080989869, diff = 00000000000000000485, tick = 00000000000000000933
Timed Action for '()':init = 00000005663080997783, stop = 00000005663080998268, diff = 00000000000000000485, tick = 00000000000000000935
Timed Action for '()':init = 00000005663081006020, stop = 00000005663081006505, diff = 00000000000000000485, tick = 00000000000000000937
Compilation finished successfully.
Edit 2: Finally fixed my lack of actual random output in that loop of mine with the help of this macro:
Code:
// https://www.geeksforgeeks.org/generating-random-number-range-c/
#define BETWEEN( MIN, MAX ) ((rand() % ((MAX) - (MIN) + 1)) + (MIN))
Output:
Code:
make run (in directory: /media/lee/ZXUIJI_1TB/github/mc)
cc -D OUT=main.elf -o main.elf main.c
./main.elf
Timed Action for 'if':init = 00000010074041966702, stop = 00000010074041967059, diff = 00000000000000000357, tick = 00000000000000000625
Timed Action for '{}':init = 00000010074042272021, stop = 00000010074042272391, diff = 00000000000000000370, tick = 00000000000000000705
Timed Action for '[]':init = 00000010074042280559, stop = 00000010074042280917, diff = 00000000000000000358, tick = 00000000000000000707
Timed Action for '()':init = 00000010074042286732, stop = 00000010074042287085, diff = 00000000000000000353, tick = 00000000000000000709
Timed Action for '()':init = 00000010074042294216, stop = 00000010074042294564, diff = 00000000000000000348, tick = 00000000000000000711
Timed Action for '[]':init = 00000010074042300333, stop = 00000010074042300742, diff = 00000000000000000409, tick = 00000000000000000712
Timed Action for '{}':init = 00000010074042306685, stop = 00000010074042307092, diff = 00000000000000000407, tick = 00000000000000000714
Timed Action for '()':init = 00000010074042312691, stop = 00000010074042313039, diff = 00000000000000000348, tick = 00000000000000000716
Timed Action for '{}':init = 00000010074042318608, stop = 00000010074042319015, diff = 00000000000000000407, tick = 00000000000000000717
Timed Action for '()':init = 00000010074042324551, stop = 00000010074042324899, diff = 00000000000000000348, tick = 00000000000000000719
Timed Action for '[]':init = 00000010074042330631, stop = 00000010074042331039, diff = 00000000000000000408, tick = 00000000000000000721
Timed Action for 'if':init = 00000010074042336775, stop = 00000010074042337121, diff = 00000000000000000346, tick = 00000000000000000722
Timed Action for '{}':init = 00000010074042342676, stop = 00000010074042343084, diff = 00000000000000000408, tick = 00000000000000000724
Timed Action for '{}':init = 00000010074042348442, stop = 00000010074042348849, diff = 00000000000000000407, tick = 00000000000000000726
Compilation finished successfully.