-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallinone.py
38 lines (27 loc) · 941 Bytes
/
allinone.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
from time import time
print("Benchmark everything in one file")
# benchmark nim in python
from quicknim import quicksort_test
start_time = time()
result = quicksort_test()
print("Nim pyd time: ", time() - start_time)
# benchmark julia in python
from juliacall import Main as jl
jl.include("quick.jl")
start_time = time()
result = jl.quicksort_test()
print("Julia in python time: ", time() - start_time)
# benchmark c from julia in python
jl.include("quick_benchmark.jl")
start_time = time()
jl.benchmark_c_quick_sort()
print("juliacall time: ", time() - start_time)
print("Notice the overhead with @ccall in Julia and also juliacall in python")
print("\nNow, let's wait for last benchmark with pure python")
# benchmark pure python
from quick import quicksort
import random
for i in range(10000):
# sort random numbers
sorted_array = quicksort(random.sample(range(1001), 1000))
print("Python time: ", time() - start_time)