# Best statistical test to use here?

I am creating an optimization function. I'll give a rundown of what it does:

Basically, the original algorithm takes a user's speed over a span of time, then calculates their average speed. It relies on 3 values, the margin of error, the # valid speeds in a row, and # of average speeds to be stored. This is how a typical run with my code would look:

Step 1) Take in speed value from user

Step 2) Check if the speed was valid (does it fall within 0.7-2.5m/s)

Step 3) Store the speed,time it was captured, and current number of valids in a row

Step 4) If 10 valids in a row, take the average of the last 10 values. Do each of the elements that make that average fall within 25% of the average? If yes store, if no disregard and continue

Step 5) Get 5 avg_speeds this way, find their average. Does each element of that final average fall within 25% of the average? If yes, that's your final speed. If no, remove all outliers and continue.

So I check with 10 valid speeds, find their average, store the average, find 5 averages this way.

That's great, but I want to optimize it now. What if 5 valid speeds was all I needed to get the same result? So what I did was, collected 3 sets of data using the most conservative of the 3 main values I could use. Now, I have allotted time and avg speeds for every variant (intervals are...valid_speeds: 3-10, avg_stored: 2-5, margin_of_error: 25%) for 3 sets of data.

What I want to know is, how would I analyze this data to determine the optimal values? I want this algorithm to be the quickest it can be, while still being fairly accurate in the final avg_speed it finds. Any tests you think I could apply to optimize this code, please help! I will include the data I have collected below, in case anyone wants to use it:

//sample: [[valids_in_a_row, num_avg_speeds_stored,time,final_avg_speed]]
var data1 = [
[ 3, 2, 53, 1.4735804398854573 ],
[ 3, 3, 83, 1.5312062899271648 ],
[ 3, 4, 96, 1.4694985747337341 ],
[ 3, 5, 112, 1.4671454906463623 ],
[ 4, 2, 56, 1.3707829862833023 ],
[ 4, 3, 78, 1.3583368758360546 ],
[ 4, 4, 86, 1.3122458532452583 ],
[ 4, 5, 97, 1.360392329096794 ],
[ 5, 2, 116, 1.305013394355774 ],
[ 5, 3, 140, 1.3103549798329672 ],
[ 5, 4, 155, 1.2562924385070802 ],
[ 5, 5, 169, 1.2136784625053407 ],
[ 6, 2, 99, 1.4751288294792175 ],
[ 6, 3, 156, 1.3421799739201863 ],
[ 6, 4, 296, 1.356351797779401 ],
[ 6, 5, 302, 1.372324737575319 ],
[ 7, 2, 100, 1.473210564681462 ],
[ 7, 3, 141, 1.4151843757856462 ],
[ 7, 4, 166, 1.3236901440790723 ],
[ 7, 5, 297, 1.3345219526972092 ],
[ 8, 2, 144, 1.3925395868718624 ],
[ 8, 3, 167, 1.2807462041576703 ],
[ 8, 4, 298, 1.30059733428061 ],
[ 8, 5, 327, 1.300560010969639 ],
[ 9, 2, 147, 1.3801151712735495 ],
[ 9, 3, 168, 1.276390587842023 ],
[ 9, 4, 299, 1.2931078804863825 ],
[ 9, 5, 328, 1.2884960227542455 ],
[ 10, 2, 169, 1.2898066073656083 ],
[ 10, 3, 300, 1.337587218483289 ],
[ 10, 4, 683, 1.473866706341505 ],
[ 10, 5, 683, 1.390336678624153 ]
]

var data2 = [
[ 3, 2, 51, 1.0832286377747853 ],
[ 3, 3, 63, 1.1146418783399794 ],
[ 3, 4, 69, 1.1305932899316151 ],
[ 3, 5, 75, 1.1014137705167133 ],
[ 4, 2, 55, 1.4472657516598701 ],
[ 4, 3, 63, 1.3834233085314434 ],
[ 4, 4, 83, 1.1193605735898018 ],
[ 4, 5, 101, 1.063455379009247 ],
[ 5, 2, 79, 1.1426099777221679 ],
[ 5, 3, 84, 1.1633643841743468 ],
[ 5, 4, 102, 1.087822387814522 ],
[ 5, 5, 107, 1.0749298677444459 ],
[ 6, 2, 69, 1.4092202683289847 ],
[ 6, 3, 103, 1.0277914537323845 ],
[ 6, 4, 115, 1.0453877860542249 ],
[ 6, 5, 115, 1.002522890843727 ],
[ 7, 2, 104, 0.9486662788050515 ],
[ 7, 3, 111, 0.9497919119134242 ],
[ 7, 4, 131, 0.9756268673405355 ],
[ 7, 5, 278, 1.0229275129279312 ],
[ 8, 2, 79, 1.1702465675771236 ],
[ 8, 3, 113, 1.0492410957813263 ],
[ 8, 4, 133, 1.0556840188801289 ],
[ 8, 5, 313, 1.1578888908028602 ],
[ 9, 2, 84, 1.113612174987793 ],
[ 9, 3, 115, 1.0031892789734733 ],
[ 9, 4, 135, 1.019960042503145 ],
[ 9, 5, 314, 1.031122186448839 ],
[ 10, 2, 107, 1.0299335300922394 ],
[ 10, 3, 315, 1.0414975623289744 ],
[ 10, 4, 364, 1.0790434315800668 ],
[ 10, 5, 885, 1.0664809250831604 ]
]
var data3 = [
[ 3, 2, 160, 1.5322645571496754 ],
[ 3, 3, 175, 1.3329402142100866 ],
[ 3, 4, 188, 1.6034752527872722 ],
[ 3, 5, 188, 1.7175567097134063 ],
[ 4, 2, 171, 1.280551090836525 ],
[ 4, 3, 171, 1.2632149135073025 ],
[ 4, 4, 243, 1.198151608929038 ],
[ 4, 5, 175, 1.4924167662858963 ],
[ 5, 2, 173, 1.4273535013198853 ],
[ 5, 3, 178, 1.5561095635096232 ],
[ 5, 4, 217, 1.4634697198867799 ],
[ 5, 5, 250, 1.348319281578064 ],
[ 6, 2, 128, 1.7534288272813514 ],
[ 6, 3, 148, 1.6711874644697449 ],
[ 6, 4, 241, 1.4820189638477232 ],
[ 6, 5, 337, 1.5190783053636552 ],
[ 7, 2, 120, 0.9819549577576774 ],
[ 7, 3, 170, 1.0212110195841106 ],
[ 7, 4, 219, 1.0827923310654504 ],
[ 7, 5, 242, 1.098556045109607 ],
[ 8, 2, 243, 1.2650236375629902 ],
[ 8, 3, 462, 1.623361532886823 ],
[ 8, 4, 517, 1.7282018512487411 ],
[ 8, 5, 563, 1.7140850365161895 ],
[ 9, 2, 244, 0.9903609719541338 ],
[ 9, 3, 634, 0.9948459311767861 ],
[ 9, 4, 1054, 1.5437883585691452 ],
[ 9, 5, 1318, 1.5231255571047464 ],
[ 10, 2, 379, 1.3240385025739672 ],
[ 10, 3, 1319, 1.7278052687644958 ],
[ 10, 4, 1319, 1.6984601974487306 ],
[ 10, 5, 1423, 1.6724854636192323 ]
]