Menu

[5c8cde]: / benchmark.py  Maximize  Restore  History

Download this file

105 lines (82 with data), 2.3 kB

  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
#!/usr/bin/env python
import sys
import os
import getopt
import operator
from time import time as now
# gettext
import gettext
os.environ.setdefault('LANG', 'en')
if os.path.isdir('po'):
gettext.install('gnofract4d','po')
else:
gettext.install('gnofract4d')
import gtk
from fract4d import fractmain, image
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):
window = main_window.MainWindow()
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):
main = fractmain.T()
print main.compiler.path_lists
times = []
last_time = now()
for file in files:
main.load(file)
im = image.T(self.w,self.h)
main.draw(im)
im.save(file + ".png")
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 "%.4f %s" % (time,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 xrange(repeats):
bench = Benchmark(useGui)
bench.run()