-
-
Save kitsuyui/67be108ecc24d5b33da2 to your computer and use it in GitHub Desktop.
基本の話: 「変数や関数を節約すればパフォーマンスが上がる」わけではない ref: http://qiita.com/kitsuyui/items/1275ba79c423f2d85530
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
printf("%d\n", 24); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.section __TEXT,__text,regular,pure_instructions | |
.globl _main | |
.align 4, 0x90 | |
_main: ## @main | |
.cfi_startproc | |
## BB#0: | |
pushq %rbp | |
Ltmp2: | |
.cfi_def_cfa_offset 16 | |
Ltmp3: | |
.cfi_offset %rbp, -16 | |
movq %rsp, %rbp | |
Ltmp4: | |
.cfi_def_cfa_register %rbp | |
subq $16, %rsp | |
leaq L_.str(%rip), %rdi | |
movl $24, %esi | |
movl $0, -4(%rbp) | |
movb $0, %al | |
callq _printf | |
movl $0, %esi | |
movl %eax, -8(%rbp) ## 4-byte Spill | |
movl %esi, %eax | |
addq $16, %rsp | |
popq %rbp | |
retq | |
.cfi_endproc | |
.section __TEXT,__cstring,cstring_literals | |
L_.str: ## @.str | |
.asciz "%d\n" | |
.subsections_via_symbols |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
int i = 1; | |
int j = 2; | |
int k = 3; | |
int l = 4; | |
int m = i * j * k * l; | |
printf("%d\n", m); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
static int x2(int x) | |
{ | |
return x * 2; | |
} | |
static int x3(int x) | |
{ | |
return x * 3; | |
} | |
static int x4(int x) | |
{ | |
return x2(x2(x)); | |
} | |
int main(void) | |
{ | |
int x = x4(x3(x2(1))); | |
printf("%d\n", x); | |
return 0; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cc --version | |
Apple LLVM version 6.0 (clang-600.0.56) (based on LLVM 3.5svn) | |
Target: x86_64-apple-darwin14.1.0 | |
Thread model: posix |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cc -c -O3 a.c b.c c.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cmp a.o b.o | |
$ cmp b.o c.o | |
$ cmp c.o a.o |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cc -O3 -S a.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cc -c -O3 -S a.c |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cmp a.o a.o | |
$ cmp a.o d.o | |
a.o d.o differ: char 1153, line 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment