and if you are curious, that's the disassembly of the code for your first version for the calculation
void test_calc_time() {
0: 0f 93 push r16
2: 1f 93 push r17
float new_x_rel;
float new_y_rel;
float new_x_abs;
float new_y_abs;
Start = micros();
4: 0e 94 00 00 call 0 ; 0x0 <_Z14test_calc_timev>
8: 60 93 00 00 sts 0x0000, r22
c: 70 93 00 00 sts 0x0000, r23
10: 80 93 00 00 sts 0x0000, r24
14: 90 93 00 00 sts 0x0000, r25
[color=red] new_x_rel = old_x_rel - (cos(theta * 0.5 * _deg_convert) * hypot);
new_y_rel = old_y_rel - (sin(theta * 0.5 * _deg_convert) * hypot);
new_x_abs = (centre_abs_x + new_x_rel);
new_y_abs = (centre_abs_y + new_y_rel);
[/color] Finish = micros();
18: 0e 94 00 00 call 0 ; 0x0 <_Z14test_calc_timev>
1c: 60 93 00 00 sts 0x0000, r22
20: 70 93 00 00 sts 0x0000, r23
24: 80 93 00 00 sts 0x0000, r24
28: 90 93 00 00 sts 0x0000, r25
You see that in red there is no math done at all
while for the second version you get all this
void next_XY_pos_circle() {
0: 4f 92 push r4
2: 5f 92 push r5
4: 6f 92 push r6
6: 7f 92 push r7
8: 8f 92 push r8
a: 9f 92 push r9
c: af 92 push r10
e: bf 92 push r11
10: cf 92 push r12
12: df 92 push r13
14: ef 92 push r14
16: ff 92 push r15
18: cf 93 push r28
1a: df 93 push r29
1c: 00 d0 rcall .+0 ; 0x1e <_Z18next_XY_pos_circlev+0x1e>
1e: 00 d0 rcall .+0 ; 0x20 <_Z18next_XY_pos_circlev+0x20>
20: cd b7 in r28, 0x3d ; 61
22: de b7 in r29, 0x3e ; 62
[color=red] float centre_abs_x = 50;
float centre_abs_y = 50;
[/color][color=blue] float theta = randNumber; // 360
24: 60 91 00 00 lds r22, 0x0000
28: 70 91 00 00 lds r23, 0x0000
2c: 80 91 00 00 lds r24, 0x0000
30: 90 91 00 00 lds r25, 0x0000
34: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
38: 69 83 std Y+1, r22 ; 0x01
3a: 7a 83 std Y+2, r23 ; 0x02
3c: 8b 83 std Y+3, r24 ; 0x03
3e: 9c 83 std Y+4, r25 ; 0x04[/color]
float new_x_rel;
float new_y_rel;
float new_x_abs;
float new_y_abs;
Start = micros();
40: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
44: 60 93 00 00 sts 0x0000, r22
48: 70 93 00 00 sts 0x0000, r23
4c: 80 93 00 00 sts 0x0000, r24
50: 90 93 00 00 sts 0x0000, r25
[color=blue]hypot = 2 * (sin(theta * 0.5 * _deg_convert) * radius);
54: 20 e0 ldi r18, 0x00 ; 0
56: 30 e0 ldi r19, 0x00 ; 0
58: 40 e0 ldi r20, 0x00 ; 0
5a: 5f e3 ldi r21, 0x3F ; 63
5c: 69 81 ldd r22, Y+1 ; 0x01
5e: 7a 81 ldd r23, Y+2 ; 0x02
60: 8b 81 ldd r24, Y+3 ; 0x03
62: 9c 81 ldd r25, Y+4 ; 0x04
64: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
68: 25 e3 ldi r18, 0x35 ; 53
6a: 3a ef ldi r19, 0xFA ; 250
6c: 4e e8 ldi r20, 0x8E ; 142
6e: 5c e3 ldi r21, 0x3C ; 60
70: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
74: 6b 01 movw r12, r22
76: 7c 01 movw r14, r24
78: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
7c: 4b 01 movw r8, r22
7e: 5c 01 movw r10, r24
80: 20 e0 ldi r18, 0x00 ; 0
82: 30 e0 ldi r19, 0x00 ; 0
84: 40 e2 ldi r20, 0x20 ; 32
86: 52 e4 ldi r21, 0x42 ; 66
88: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
8c: 9b 01 movw r18, r22
8e: ac 01 movw r20, r24
90: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
94: 2b 01 movw r4, r22
96: 3c 01 movw r6, r24
new_x_rel = old_x_rel - (cos(theta * 0.5 * _deg_convert) * hypot);
98: c7 01 movw r24, r14
9a: b6 01 movw r22, r12
9c: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
a0: a3 01 movw r20, r6
a2: 92 01 movw r18, r4
a4: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
a8: 9b 01 movw r18, r22
aa: ac 01 movw r20, r24
ac: 60 e0 ldi r22, 0x00 ; 0
ae: 70 e0 ldi r23, 0x00 ; 0
b0: cb 01 movw r24, r22
b2: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
b6: 6b 01 movw r12, r22
b8: 7c 01 movw r14, r24
new_y_rel = old_y_rel - (sin(theta * 0.5 * _deg_convert) * hypot);
ba: a3 01 movw r20, r6
bc: 92 01 movw r18, r4
be: c5 01 movw r24, r10
c0: b4 01 movw r22, r8
c2: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
c6: 9b 01 movw r18, r22
c8: ac 01 movw r20, r24
ca: 60 e0 ldi r22, 0x00 ; 0
cc: 70 e0 ldi r23, 0x00 ; 0
ce: 80 e2 ldi r24, 0x20 ; 32
d0: 92 e4 ldi r25, 0x42 ; 66
d2: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
d6: 4b 01 movw r8, r22
d8: 5c 01 movw r10, r24
new_x_abs = (centre_abs_x + new_x_rel);
new_y_abs = (centre_abs_y + new_y_rel);
[/color]
Finish = micros();
da: 0e 94 00 00 call 0 ; 0x0 <_Z18next_XY_pos_circlev>
de: 60 93 00 00 sts 0x0000, r22
e2: 70 93 00 00 sts 0x0000, r23
e6: 80 93 00 00 sts 0x0000, r24
ea: 90 93 00 00 sts 0x0000, r25
in red you have still static pre compiler allocation but you do the math in blue, which is where the bulk of the time goes.