들어가며
오늘의 키워드
A==NULL 과 !A 는 성능차이가 있을까
if (new_node == NULL) {
00625204 cmp dword ptr [new_node],0
00625208 jne __$EncStackInitStart+50h (062521Ch)
exit(1);
0062520A mov esi,esp
0062520C push 1
0062520E call dword ptr [__imp__exit (062C144h)]
00625214 cmp esi,esp
00625216 call __RTC_CheckEsp (0621271h)
0062521B nop
}
if (!new_node) {
0062521C cmp dword ptr [new_node],0
00625220 jne __$EncStackInitStart+68h (0625234h)
exit(1);
00625222 mov esi,esp
00625224 push 1
00625226 call dword ptr [__imp__exit (062C144h)]
0062522C cmp esi,esp
0062522E call __RTC_CheckEsp (0621271h)
00625233 nop
}
짜잔, 성능차이가 없었습니다! 마음 편하게 내가 원하는 방식을 선택하면 되는 것으로 보인다.
변수의 반복문 안 선언이 성능을 떨어트릴까
for(~~) {
int input;
scanf("%d", &input);
}
int input;
for(~~) {
scanf("%d", &input);
}
어셈블리를 까봤떠니, 결과적으로는 내부에 선언했을 때와 외부에 선언했을 때 차이가 발생하지 않았다. 물론 메모리 공간도 같은 함수 내부에 사용했다면 미리 할당받아두기 때문에 메모리 stack을 옮기는 연산도 발생하지 않는다.
안전한 변수 사용을 위해 block 내부에 선언하는 방식을 사용해야겠다. 물론 개인의 취향이니,,, 팀 컨벤션에 맞추겠다~!
for (int i = 0; i < N; i++) {
00C21EE1 mov dword ptr [ebp-30h],0
00C21EE8 jmp __$EncStackInitStart+87h (0C21EF3h)
00C21EEA mov eax,dword ptr [ebp-30h]
00C21EED add eax,1
00C21EF0 mov dword ptr [ebp-30h],eax
00C21EF3 mov eax,dword ptr [ebp-30h]
00C21EF6 cmp eax,dword ptr [N]
00C21EF9 jge __$EncStackInitStart+0A2h (0C21F0Eh)
int input;
(void)scanf("%d", &input);
00C21EFB lea eax,[ebp-3Ch]
00C21EFE push eax
00C21EFF push offset string "%d" (0C28B4Ch)
00C21F04 call _scanf (0C21037h)
00C21F09 add esp,8
}
00C21F0C jmp __$EncStackInitStart+7Eh (0C21EEAh)
int input2;
for (int i = 0; i < N; i++) {
00C21F0E mov dword ptr [ebp-54h],0
00C21F15 jmp __$EncStackInitStart+0B4h (0C21F20h)
00C21F17 mov eax,dword ptr [ebp-54h]
00C21F1A add eax,1
00C21F1D mov dword ptr [ebp-54h],eax
00C21F20 mov eax,dword ptr [ebp-54h]
00C21F23 cmp eax,dword ptr [N]
00C21F26 jge __$EncStackInitStart+0CFh (0C21F3Bh)
(void)scanf("%d", &input2);
00C21F28 lea eax,[input2]
00C21F2B push eax
00C21F2C push offset string "%d" (0C28B4Ch)
00C21F31 call _scanf (0C21037h)
00C21F36 add esp,8
}
00C21F39 jmp __$EncStackInitStart+0ABh (0C21F17h)320x100
'TIL' 카테고리의 다른 글
| [250922] Day 42 - 신호및시스템 시작 (0) | 2025.09.23 |
|---|---|
| [250912] Day 33 - 텔레칩스 임베디드 스쿨 1달 리뷰 (1) | 2025.09.17 |
| [250905] Day 26 - 죽이고싶은 BFS 문제와의 10선 (0) | 2025.09.10 |
| [250903] Day 24 - 임베디드 스터디 ON (0) | 2025.09.04 |
| [250902] Day 23 - 이제 내 세상이다 (0) | 2025.09.04 |