-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
47 lines (36 loc) · 1.21 KB
/
benchmark.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
39
40
41
42
43
44
45
46
47
import core, hdf5, text_test
import time, hotshot
# NB: hotshot.stats is imported in the print profile
# Function (see note there)
def converge_150():
prof = hotshot.Profile("150-test-profile.prof")
start_time = time.time()
prof.start()
s = text_test.test_array
test_sol = core.Solver(s, (1,0), printing = 2, sol_method = "bicgstab")
test_sol.converge()
prof.stop()
return time.time() - start_time
def converge_150_direct():
prof = hotshot.Profile("150-test-profile.prof")
start_time = time.time()
prof.start()
s = text_test.test_array
test_sol = core.Solver(s, (1,0), printing = 2)
test_sol.monolithic_solve()
prof.stop()
return time.time() - start_time
def print_profile(profile_path):
# .stats needs extra package (python-profile)
# so relative import is here
# Ergo stats analysis on home computer only!
import hotshot.stats
stats = hotshot.stats.load(profile_path)
stats.strip_dirs()
stats.sort_stats('time', 'calls')
stats.print_stats(40)
if __name__ == "__main__":
print "Running a stress test . . ."
fin_time = converge_150()
print "Time to finish:", fin_time
print "Profile written to '150-test-profile.prof'"