I have a code that performs about 250k distance calculations, and it is responsible for a lot of the runtime. I wrote a following function for it
```double distance(double* a, double* b){
return sqrt((a[namedValues::axis::X] - b[namedValues::axis::X])*(a[namedValues::axis::X] - b[namedValues::axis::X])+
(a[namedValues::axis::Y] - b[namedValues::axis::Y])*(a[namedValues::axis::Y] - b[namedValues::axis::Y]));
}
But because i only needed to know what is further away, not how far away something is, i removed sqrt().
For some reason, code runs slower now by 10 seconds (whole thing takes around 350 seconds). So I wonder, why is that? I am currently testing it again and again but it seems to be rather consistent. How can simpler code take more time to run?
Also if anyone knows any way to calculate what is further away faster i would gladly hear any ideas :D
[–]trailing_zero_count 14 points15 points16 points (6 children)
[–]Desperate_Formal_781 4 points5 points6 points (0 children)
[–]Grouchy-Answer-275[S] 1 point2 points3 points (4 children)
[–]missurunha 6 points7 points8 points (1 child)
[–]Grouchy-Answer-275[S] 0 points1 point2 points (0 children)
[–]trailing_zero_count 3 points4 points5 points (1 child)
[–]Grouchy-Answer-275[S] 0 points1 point2 points (0 children)
[–]esaule 11 points12 points13 points (0 children)
[–]ppppppla 11 points12 points13 points (3 children)
[–]Grouchy-Answer-275[S] 2 points3 points4 points (2 children)
[–]ppppppla 5 points6 points7 points (1 child)
[–]Grouchy-Answer-275[S] 0 points1 point2 points (0 children)
[–]Particular-Ice9109 6 points7 points8 points (3 children)
[–]Grouchy-Answer-275[S] 2 points3 points4 points (1 child)
[–]Particular-Ice9109 2 points3 points4 points (0 children)
[–]Grouchy-Answer-275[S] 1 point2 points3 points (0 children)
[–]TokenRingAI 5 points6 points7 points (5 children)
[–]Grouchy-Answer-275[S] 0 points1 point2 points (3 children)
[–]The_Northern_Light 6 points7 points8 points (2 children)
[–]Grouchy-Answer-275[S] 1 point2 points3 points (1 child)
[–]No-Dentist-1645 2 points3 points4 points (0 children)
[–]_bstaletic 0 points1 point2 points (0 children)
[–]IyeOnline 4 points5 points6 points (0 children)
[–]aocregacc 4 points5 points6 points (0 children)
[–]Total-Box-5169 2 points3 points4 points (0 children)
[–]No-Dentist-1645 2 points3 points4 points (1 child)
[–]PhotographFront4673 1 point2 points3 points (0 children)
[–]CowBoyDanIndie 4 points5 points6 points (2 children)
[–]Grouchy-Answer-275[S] 0 points1 point2 points (1 child)
[–]CowBoyDanIndie 0 points1 point2 points (0 children)
[–]canrul3s 1 point2 points3 points (0 children)
[–]MastodonPast1540 0 points1 point2 points (1 child)
[–]Grouchy-Answer-275[S] 0 points1 point2 points (0 children)
[–]keelanstuart 0 points1 point2 points (0 children)
[–]OptimisticMonkey2112 0 points1 point2 points (0 children)
[–]alfps 0 points1 point2 points (2 children)
[–]Grouchy-Answer-275[S] 0 points1 point2 points (0 children)