Skip to content

Commit 3a36be7

Browse files
author
Jacob Austin
committed
Added benchmark markdown file
1 parent 4447f83 commit 3a36be7

File tree

2 files changed

+165
-0
lines changed

2 files changed

+165
-0
lines changed

benchmark.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Benchmarks
2+
3+
This file contains benchmarks and results for Coral. These benchmarks are not intended
4+
to be exhaustive, but simply indicative of some advantages of Coral over Python or C.
5+
6+
All benchmarks were performed on a 2015 Macbook Pro running Mac OS Catalina on a 2.7 GHz
7+
Dual-Core Intel Core i5 with 8GB of RAM.
8+
9+
## GCD Benchmark
10+
11+
Here we attempt to compute the gcd of two numbers in C, Python, and Coral.
12+
13+
### Source Code
14+
15+
The C source code is as follows:
16+
17+
```c
18+
#include <stdio.h>
19+
20+
long gcd(long a, long b) {
21+
while (a != b) {
22+
if (a > b) {
23+
a = a - b;
24+
} else {
25+
b = b - a;
26+
}
27+
}
28+
29+
return a;
30+
}
31+
32+
int main(int argc, char ** argv) {
33+
long a = 90;
34+
long b = 800052312523;
35+
long result = gcd(a, b);
36+
}
37+
```
38+
39+
The C code will be compiled with `gcc -O1/2/3` or `clang -O1/2/3` for comparison.
40+
41+
The Coral/Python code is as follows:
42+
43+
```python
44+
def gcd(a : int, b : int):
45+
while a != b:
46+
if a > b:
47+
a = a - b
48+
else:
49+
b = b - a
50+
return a
51+
52+
a = 90
53+
b = 800052312523
54+
result = gcd(a, b)
55+
```
56+
57+
Note that we do not need type hints here, since it can be fully type inferred without.
58+
59+
### Results
60+
61+
Our results are as follows:
62+
63+
**Coral:**
64+
65+
Results are from `coral -o gcd -S gcd.py` and then `gcc -O1/2/3 gcd.s` then
66+
`time ./a.out`. This allows us to compare different optimizations using GCC. I also
67+
tested having Coral emit LLVM and compiling that with Clang, which produced similar
68+
results.
69+
70+
**-O0:**
71+
72+
```
73+
real 0m0.033s
74+
user 0m0.028s
75+
sys 0m0.002s
76+
```
77+
78+
**O1:**
79+
80+
```
81+
real 0m0.033s
82+
user 0m0.028s
83+
sys 0m0.002s
84+
```
85+
86+
**O2:**
87+
88+
```
89+
real 0m0.034s
90+
user 0m0.029s
91+
sys 0m0.002s
92+
```
93+
94+
**O3:**
95+
96+
```
97+
real 0m0.031s
98+
user 0m0.027s
99+
sys 0m0.002s
100+
```
101+
102+
**C:**
103+
104+
Results are from `gcc -O1/2/3 -o gcc gcc.c` and then `time ./gcd`.
105+
106+
**-O0:**
107+
108+
```
109+
real 0m21.061s
110+
user 0m17.938s
111+
sys 0m0.120s
112+
```
113+
114+
**-O1:**
115+
116+
```
117+
real 0m19.983s
118+
user 0m17.693s
119+
sys 0m0.140s
120+
```
121+
122+
**-O2:**
123+
124+
```
125+
real 0m0.004s
126+
user 0m0.001s
127+
sys 0m0.002s
128+
```
129+
130+
**-O3:**
131+
132+
```
133+
real 0m0.004s
134+
user 0m0.001s
135+
sys 0m0.002s
136+
```
137+
138+
**Python:**
139+
140+
Results are from `time python gcd.py`
141+
142+
```
143+
real 13m46.220s
144+
user 12m57.995s
145+
sys 0m3.848s
146+
```

demos/gcd.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#include <stdio.h>
2+
3+
long gcd(long a, long b) {
4+
while (a != b) {
5+
if (a > b) {
6+
a = a - b;
7+
} else {
8+
b = b - a;
9+
}
10+
}
11+
12+
return a;
13+
}
14+
15+
int main(int argc, char ** argv) {
16+
long a = 90;
17+
long b = 800052312523;
18+
long result = gcd(a, b);
19+
}

0 commit comments

Comments
 (0)