robtillaart:
I do not have time to test it , 3 questions:
Can you post the output ?
how about the footprint? smaller / larger same?
A sample output is:
Loop FastTime(us)=28 SlowTime(us)=64 value=197 median=0 excactmedian=175
Loop FastTime(us)=24 SlowTime(us)=92 value=114 median=0 excactmedian=158
Loop FastTime(us)=24 SlowTime(us)=104 value=68 median=0 excactmedian=158
Loop FastTime(us)=36 SlowTime(us)=124 value=188 median=0 excactmedian=158
Loop FastTime(us)=28 SlowTime(us)=144 value=109 median=0 excactmedian=158
Loop FastTime(us)=32 SlowTime(us)=168 value=120 median=0 excactmedian=120
Loop FastTime(us)=32 SlowTime(us)=196 value=80 median=0 excactmedian=120
Loop FastTime(us)=32 SlowTime(us)=232 value=102 median=0 excactmedian=114
Loop FastTime(us)=32 SlowTime(us)=256 value=47 median=0 excactmedian=114
Loop FastTime(us)=36 SlowTime(us)=288 value=102 median=0 excactmedian=109
Loop FastTime(us)=52 SlowTime(us)=340 value=143 median=19 excactmedian=114
Loop FastTime(us)=52 SlowTime(us)=364 value=142 median=38 excactmedian=114
Loop FastTime(us)=36 SlowTime(us)=404 value=79 median=47 excactmedian=114
Loop FastTime(us)=64 SlowTime(us)=444 value=160 median=68 excactmedian=114
Loop FastTime(us)=40 SlowTime(us)=492 value=52 median=68 excactmedian=114
Loop FastTime(us)=32 SlowTime(us)=524 value=3 median=68 excactmedian=109
Loop FastTime(us)=68 SlowTime(us)=576 value=124 median=79 excactmedian=114
Loop FastTime(us)=60 SlowTime(us)=624 value=114 median=80 excactmedian=114
Loop FastTime(us)=36 SlowTime(us)=676 value=32 median=80 excactmedian=114
Loop FastTime(us)=52 SlowTime(us)=724 value=70 median=80 excactmedian=109
Loop FastTime(us)=40 SlowTime(us)=784 value=18 median=80 excactmedian=109
Loop FastTime(us)=96 SlowTime(us)=856 value=189 median=102 excactmedian=109
Loop FastTime(us)=88 SlowTime(us)=900 value=123 median=102 excactmedian=114
Loop FastTime(us)=76 SlowTime(us)=972 value=116 median=109 excactmedian=114
Loop FastTime(us)=108 SlowTime(us)=1036 value=190 median=114 excactmedian=114
Loop FastTime(us)=116 SlowTime(us)=1104 value=247 median=114 excactmedian=114
Loop FastTime(us)=60 SlowTime(us)=1164 value=56 median=114 excactmedian=114
Loop FastTime(us)=80 SlowTime(us)=1164 value=17 median=114 excactmedian=114
Loop FastTime(us)=96 SlowTime(us)=1168 value=157 median=114 excactmedian=114
Loop FastTime(us)=32 SlowTime(us)=1168 value=230 median=114 excactmedian=114
Loop FastTime(us)=52 SlowTime(us)=1164 value=3 median=114 excactmedian=114
Loop FastTime(us)=24 SlowTime(us)=1164 value=139 median=114 excactmedian=114
Loop FastTime(us)=56 SlowTime(us)=1164 value=79 median=114 excactmedian=114
Loop FastTime(us)=56 SlowTime(us)=1172 value=204 median=114 excactmedian=114
Loop FastTime(us)=36 SlowTime(us)=1168 value=66 median=114 excactmedian=114
Loop FastTime(us)=68 SlowTime(us)=1172 value=22 median=109 excactmedian=109
Loop FastTime(us)=60 SlowTime(us)=1164 value=167 median=114 excactmedian=114
Loop FastTime(us)=52 SlowTime(us)=1164 value=208 median=114 excactmedian=114
Loop FastTime(us)=48 SlowTime(us)=1172 value=141 median=116 excactmedian=116
Loop FastTime(us)=48 SlowTime(us)=1172 value=155 median=123 excactmedian=123
Loop FastTime(us)=64 SlowTime(us)=1172 value=125 median=124 excactmedian=124
Loop FastTime(us)=60 SlowTime(us)=1164 value=158 median=125 excactmedian=125
for the first n rounds the result values are incorrect, but afterwards they are identical. Your code takes around 1170us, mine below 100us in most cases. Your timing is more stable
Size of code is almost identical, my code a tiny bit smaller. I am not sure if this depends on the data type.
Static memory and stack usage is also more or less the same.
Your add-method is fast, the median calculation is slow.
My add-method does the whole work, my median returning is fast.
If you add a lot of values and retrieve the median only seldom there is maybe a speed advantage with your method.
Thank you for your feedback - rk