annotate paper/chapter5.tex @ 17:3afb4bfe1100

fix
author Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
date Mon, 15 Feb 2016 07:30:44 +0900
parents a077276f53cc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 \chapter{評価・考察}
10
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
2 今回の研究で改良を行ったた LLVM/clang 上での CbC コンパイラの評価を試みる. 評価は, コンパイルして出力されたアセンブリコードの確認, 改良前の LLVM, 改良後の LLVM, Micro-C, GCC でコンパイルして得られたプログラムによる実行速度の比較, C で実装した類似のプログラムとの速度比較により行う.
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 \section{アセンブリコードの評価}
8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
4 以下のリスト \ref{evalCbC},\ref{evalAsmB}, \ref{evalAsmA} はそれぞれコンパイル前の CbC の code segment とコンパイル後のアセンブリコードを示している. リスト \ref{evalAsmB} は omit leaf frame pointer 強制前のアセンブリコード, リスト \ref{evalAsmA} は omit leaf frame pointer 強制後のアセンブリコードである. リスト \ref{evalAsmB} には push, pop 命令によるフレームポインタの操作が入っているのに対し, リスト \ref{evalAsmA} にはその操作がない. このことから, omit leaf frame pointer が正しく動作していることがわかる.
7
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
5 \begin{lstlisting}[frame=lrbt,label=evalCbC,caption={コンパイル前}]
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
6 __code f(int i,stack sp) {
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
7 int k,j;
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
8 k = 3+i;
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
9 goto f_g0(i,k,sp);
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
10 }
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
11 \end{lstlisting}
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
12
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
13 \begin{lstlisting}[frame=lrbt,label=evalAsmB,caption={omit leaf frame pointer 強制前}]
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
14 _f: ## @f
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
15 .cfi_startproc
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
16 ## BB#0: ## %entry
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
17 pushq %rbp
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
18 Ltmp9:
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
19 .cfi_def_cfa_offset 16
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
20 Ltmp10:
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
21 .cfi_offset %rbp, -16
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
22 movq %rsp, %rbp
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
23 Ltmp11:
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
24 .cfi_def_cfa_register %rbp
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
25 movl %edi, %eax
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
26 addl $3, %eax
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
27 movq %rsi, -8(%rbp) ## 8-byte Spill
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
28 movl %eax, %esi
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
29 movq -8(%rbp), %rdx ## 8-byte Reload
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
30 popq %rbp
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
31 jmp _f_g0 ## TAILCALL
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
32 .cfi_endproc
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
33 \end{lstlisting}
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
34
8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
35 \begin{lstlisting}[frame=lrbt,label=evalAsmA,caption={omit leaf frame pointer 強制後}]
7
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
36 _f: ## @f
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
37 .cfi_startproc
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
38 ## BB#0: ## %entry
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
39 subq $24, %rsp
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
40 Ltmp9:
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
41 .cfi_def_cfa_offset 32
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
42 movl %edi, %eax
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
43 addl $3, %eax
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
44 movq %rsi, 16(%rsp) ## 8-byte Spill
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
45 movl %eax, %esi
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
46 movq 16(%rsp), %rdx ## 8-byte Reload
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
47 addq $24, %rsp
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
48 jmp _f_g0 ## TAILCALL
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
49 .cfi_endproc
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
50 \end{lstlisting}
5f0a5e8cb3cc change style
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 6
diff changeset
51
8
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 7
diff changeset
52 \section{実行速度の評価}
17
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
53 今回測定に使用したプログラムは環境付き継続と計算を繰り返すプログラムである(リスト \ref{gotowithenv}). 測定は x86-84 アーキテクチャの OS X 上で行った. 表 \ref{result} が測定結果である.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
54
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
55 \begin{lstlisting}[frame=lrbt,label=gotowithenv,caption={環境付き継続を繰り返すプログラム}]
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
56 #define LOOP 50000000
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
57
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
58 #include <stdio.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
59
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
60 __code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(int, void*),void*exit1env);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
61
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
62 __code factorial(int n,int result,int orig,__code(*print)(int,int,int,__code(*)(),__code(*)(),void*),__code(*exit1)(int,void *), void *exit1env)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
63 {
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
64 if (n<0) {
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
65 printf("#0008:err %d!\n",n);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
66 goto (*exit1)(0,exit1env);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
67 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
68 if (n==0)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
69 goto (*print)(n,result,orig,print,exit1,exit1env);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
70 else {
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
71 result += n;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
72 n--;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
73 goto factorial(n,result,orig,print,exit1,exit1env);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
74 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
75 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
76
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
77
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
78 int calc(int n){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
79 __code (*ret)(int,void *) = __return;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
80 void* env = __environment;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
81 goto factorial(n,1,n,print,ret,env);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
82 return 0;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
83 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
84
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
85 int main( int ac, char *av[])
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
86 {
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
87 int i;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
88 long ans;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
89 for(i=LOOP,ans=0;i>0;i--){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
90 ans += calc(10);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
91 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
92
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
93 printf("%ld\n",ans);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
94 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
95
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
96 __code print(int n,int result,int orig,__code(*print)(),__code (*exit1)(int, void*),void*exit1env)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
97 {
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
98 goto (*exit1)(result,exit1env);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
99 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
100 \end{lstlisting}
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
101
10
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
102 \begin{table}[htpb]
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
103 \centering
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
104 \begin{tabular}{|l|r|} \hline
17
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
105 コンパイラ名 & 実行速度 (s) \\ \hline
10
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
106 LLVM/clang & 3.35 \\ \hline
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
107 LLVM/clang -O2 & 1.30 \\ \hline
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
108 LLVM/clang (old) & 23.30 \\ \hline
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
109 Micro-C & 1.29 \\ \hline
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
110 GCC & 14.73 \\ \hline
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
111 GCC -O2 & 12.96 \\ \hline
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
112 \end{tabular}
17
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
113 \caption{Mac OS X での Micro-C, GCC, LLVM/clang の環境付き継続の速度比較}
10
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
114 \label{result}
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
115 \end{table}
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
116
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
117
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
118 結果から、改良前の LLVM/clang とくらべて現在のものが最適化込みで 10 倍以上, 最適化を除いても 7 倍近い速度が出ていることがわかる. このことから通常の setjmp, longjmp の処理の重さが伺える. また, GCC のコンパイラの速度を大きく上回っていることから, nested function を用いた実装よりもこちらのほうが速いということがわかる. Micro-C コンパイラは直接アセンブラを生成しているので非常に高速であるが, 最適化を利用することで同等の速度が実現できている.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
119
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
120 \section{C, Scheme との比較}
17
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
121 CbC と他の言語との比較を行う. 比較対象は C, 継続を用いることのできる Scheme とした. Scheme のコンパイラには Chicken を使用した.
0
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents:
diff changeset
122
17
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
123 比較に使用したプログラムは C の関数呼び出し, CbC の軽量継続, Scheme の継続 を繰り返し行うものである (リスト \ref{calc}, \ref{calcCbC}, \ref{calcScheme}).
10
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
124
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
125 結果は以下のようになった.
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
126
17
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
127 \begin{lstlisting}[frame=lrbt,label=calc,caption={Cの計測用コード}]
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
128 #define LOOP 500000000
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
129
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
130 #include <stdio.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
131 #include <stdlib.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
132
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
133 int func4(int a, int b){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
134 return a+b;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
135 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
136
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
137 int func3(int a, int b){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
138 return func4(b,b/a);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
139 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
140
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
141 int func2(int a, int b){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
142 return func3(b,a*b);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
143 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
144
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
145 int func1(int a, int b){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
146 return func2(b,a+b);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
147 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
148
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
149 int start_func(int loop){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
150 int i, a;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
151 a = 0;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
152 for (i=0;i<loop;i++)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
153 a += func1(1,2);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
154 return a;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
155 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
156
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
157 int main( int ac, char *av[]){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
158 printf("%d\n",start_func(LOOP));
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
159 return 0;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
160 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
161 \end{lstlisting}
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
162
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
163 \begin{lstlisting}[frame=lrbt,label=calcCbC,caption={CbCの計測用コード}]
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
164 #define LOOP 500000000
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
165
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
166 #include <stdio.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
167 #include <stdlib.h>
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
168
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
169 __code code4(int a, int b, int loop, int ans){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
170 goto start_code(ans+a+b, loop-1);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
171 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
172
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
173 __code code3(int a, int b, int loop, int ans){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
174 goto code4(b,b/a,loop, ans);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
175 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
176
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
177 __code code2(int a, int b, int loop, int ans){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
178 goto code3(b,a*b,loop, ans);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
179 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
180
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
181 __code code1(int a, int b, int loop, int ans){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
182 goto code2(b,a+b,loop, ans);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
183 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
184
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
185 __code start_code(int ans, int loop){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
186 if (loop>0)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
187 goto code1(1,2,loop, ans);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
188 else
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
189 goto print(ans);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
190 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
191
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
192 int main( int ac, char *av[]){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
193 goto start_code(0,LOOP);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
194 return 0;
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
195 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
196
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
197 __code print(int a){
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
198 printf("%d\n",a);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
199 exit(0);
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
200 }
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
201 \end{lstlisting}
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
202
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
203 \begin{lstlisting}[frame=lrbt,label=calcScheme,caption={Schemeの測定用コード}]
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
204 (define LOOP 500000000)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
205
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
206 (define (print_ans ans)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
207 (print ans))
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
208
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
209 (define (code4 a b loop ans)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
210 (start_code (+ ans (+ a b)) (- loop 1)))
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
211
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
212 (define (code3 a b loop ans)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
213 (code4 b (/ b a) loop ans))
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
214
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
215 (define (code2 a b loop ans)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
216 (code3 b (* a b) loop ans))
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
217
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
218 (define (code1 a b loop ans)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
219 (code2 b (+ a b) loop ans))
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
220
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
221 (define (start_code ans loop)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
222 (if (> loop 0) (code1 1 2 loop ans) (print_ans ans) ))
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
223
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
224 (start_code 0 LOOP)
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
225 \end{lstlisting}
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
226
10
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
227 \begin{table}[htpb]
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
228 \centering
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
229 \begin{tabular}{|l|r|} \hline
17
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
230 言語 & 実行速度 (s) \\ \hline
10
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
231 C & 4.85 \\ \hline
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
232 CbC & 3.10 \\ \hline
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
233 Scheme & 39.24 \\ \hline
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
234 \end{tabular}
17
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 12
diff changeset
235 \caption{Mac OS X での C, CbC, Scheme の実行速度比較}
12
a077276f53cc add graph
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 10
diff changeset
236 \label{comp}
10
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
237 \end{table}
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 8
diff changeset
238
12
a077276f53cc add graph
Kaito Tokumori <e105711@ie.u-ryukyu.ac.jp>
parents: 10
diff changeset
239 結果より, CbC の軽量継続が関数呼び出しよりも高速であることがわかる. このことからも関数呼び出し, return の際に行われるスタック操作の処理の重さがわかるだろう.