-
Notifications
You must be signed in to change notification settings - Fork 27
/
benchmark.py
executable file
·109 lines (89 loc) · 2.57 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/usr/bin/env python3
import gettext
import operator
import os
import sys
from functools import reduce
from time import time as now
os.environ.setdefault('LANG', 'en')
if os.path.isdir('po'):
gettext.install('gnofract4d', 'po')
else:
gettext.install('gnofract4d')
import gi
gi.require_version('Gtk', '3.0')
try:
from gi.repository import Gtk
except ImportError:
print(_("Can't find Gtk. You need to install it before you can run Gnofract 4D."))
sys.exit(1)
from fract4d import fractmain, fractconfig
from fract4d.options import Arguments
from fract4dgui import main_window
files = [
'testdata/std.fct',
'testdata/param.fct',
'testdata/valley_test.fct',
'testdata/trigcentric.fct',
'testdata/zpower.fct'
]
class Benchmark:
def __init__(self, useGui):
self.last_time = None
self.pos = 0
self.useGui = useGui
self.w = 320
self.h = 240
def run_gui(self):
application = Gtk.Application()
application.userConfig = fractconfig.userConfig()
window = main_window.MainWindow(application)
window.f.set_size(self.w, self.h)
window.f.thaw()
times = []
self.last_time = now()
def status_changed(f, status):
if status == 0:
# done
new_time = now()
times.append(new_time - self.last_time)
self.last_time = new_time
self.pos += 1
if self.pos < len(files):
window.load(files[self.pos])
else:
Gtk.main_quit()
window.f.connect('status-changed', status_changed)
window.load(files[0])
Gtk.main()
return times
def run_nogui(self):
userConfig = fractconfig.userConfig()
main = fractmain.T(userConfig)
times = []
last_time = now()
for file in files:
main.load(file)
opts = Arguments().parse_args(sys.argv[1:])
main.run(opts)
new_time = now()
times.append(new_time - last_time)
return times
def run(self):
if self.useGui:
times = self.run_gui()
else:
times = self.run_nogui()
for (file, time) in zip(files, times):
print(f"{time:.4f} {file}")
print(reduce(operator.__add__, times, 0))
useGui = True
repeats = 1
for arg in sys.argv[1:]:
if arg == "--nogui":
useGui = False
if arg == "--repeat":
repeats = 3
for i in range(repeats):
bench = Benchmark(useGui)
bench.run()