/usr/share/pyshared/kivy/tools/benchmark.py is in python-kivy 1.7.2-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | '''
Benchmark
=========
'''
benchmark_version = '1'
import os
import sys
import json
import kivy
import gc
from time import clock, time, ctime
from random import randint
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.widget import Widget
from kivy.graphics import RenderContext
from kivy.input.motionevent import MotionEvent
from kivy.cache import Cache
from kivy.clock import Clock
clockfn = time
if sys.platform == 'win32':
clockfn = clock
class FakeMotionEvent(MotionEvent):
pass
class bench_widget_creation:
'''Widget: creation (10000 Widget)'''
def run(self):
o = []
for x in xrange(10000):
o.append(Widget())
class bench_widget_creation_with_root:
'''Widget: creation (10000 Widget + 1 root)'''
def run(self):
o = Widget()
for x in xrange(10000):
o.add_widget(Widget())
class bench_widget_draw:
'''Widget: empty drawing (10000 Widget + 1 root)'''
def __init__(self):
self.ctx = RenderContext()
self.root = root = Widget()
for x in xrange(10000):
root.add_widget(Widget())
self.ctx.add(self.root.canvas)
def run(self):
self.ctx.draw()
class bench_widget_dispatch:
'''Widget: event dispatch (1000 on_update in 10*1000 Widget)'''
def __init__(self):
root = Widget()
for x in xrange(10):
parent = Widget()
for y in xrange(1000):
parent.add_widget(Widget())
root.add_widget(parent)
self.root = root
def run(self):
touch = FakeMotionEvent('fake', 1, [])
self.root.dispatch('on_touch_down', touch)
self.root.dispatch('on_touch_move', touch)
self.root.dispatch('on_touch_up', touch)
class bench_label_creation:
'''Core: label creation (10000 * 10 a-z)'''
def __init__(self):
labels = []
for x in xrange(10000):
label = map(lambda x: chr(randint(ord('a'), ord('z'))), xrange(10))
labels.append(''.join(label))
self.labels = labels
def run(self):
o = []
for x in self.labels:
o.append(Label(text=x))
class bench_button_creation:
'''Core: button creation (10000 * 10 a-z)'''
def __init__(self):
labels = []
for x in xrange(10000):
button = map(lambda x: chr(randint(ord('a'), ord('z'))), xrange(10))
labels.append(''.join(button))
self.labels = labels
def run(self):
o = []
for x in self.labels:
o.append(Button(text=x))
class bench_label_creation_with_tick:
'''Core: label creation (10000 * 10 a-z), with Clock.tick'''
def __init__(self):
labels = []
for x in xrange(10000):
label = map(lambda x: chr(randint(ord('a'), ord('z'))), xrange(10))
labels.append(''.join(label))
self.labels = labels
def run(self):
o = []
for x in self.labels:
o.append(Label(text=x))
# tick for texture creation
Clock.tick()
class bench_button_creation_with_tick:
'''Core: button creation (10000 * 10 a-z), with Clock.tick'''
def __init__(self):
labels = []
for x in xrange(10000):
button = map(lambda x: chr(randint(ord('a'), ord('z'))), xrange(10))
labels.append(''.join(button))
self.labels = labels
def run(self):
o = []
for x in self.labels:
o.append(Button(text=x))
# tick for texture creation
Clock.tick()
if __name__ == '__main__':
report = []
report_newline = True
def log(s, newline=True):
global report_newline
if not report_newline:
report[-1] = '%s %s' % (report[-1], s)
else:
report.append(s)
if newline:
print s
report_newline = True
else:
print s,
report_newline = False
sys.stdout.flush()
clock_total = 0
benchs = locals().keys()
benchs.sort()
benchs = [locals()[x] for x in benchs if x.startswith('bench_')]
log('')
log('=' * 70)
log('Kivy Benchmark v%s' % benchmark_version)
log('=' * 70)
log('')
log('System informations')
log('-------------------')
log('OS platform : %s' % sys.platform)
log('Python EXE : %s' % sys.executable)
log('Python Version : %s' % sys.version)
log('Python API : %s' % sys.api_version)
log('Kivy Version : %s' % kivy.__version__)
log('Install path : %s' % os.path.dirname(kivy.__file__))
log('Install date : %s' % ctime(os.path.getctime(kivy.__file__)))
log('')
log('OpenGL informations')
log('-------------------')
from kivy.core.gl import glGetString, GL_VENDOR, GL_RENDERER, GL_VERSION
log('GL Vendor: %s' % glGetString(GL_VENDOR))
log('GL Renderer: %s' % glGetString(GL_RENDERER))
log('GL Version: %s' % glGetString(GL_VERSION))
log('')
log('Benchmark')
log('---------')
for x in benchs:
# clean cache to prevent weird case
for cat in Cache._categories:
Cache.remove(cat)
# force gc before next test
gc.collect()
log('%2d/%-2d %-60s' % (benchs.index(x) + 1,
len(benchs), x.__doc__), False)
try:
sys.stderr.write('.')
test = x()
except Exception, e:
log('failed %s' % str(e))
import traceback
traceback.print_exc()
continue
clock_start = clockfn()
try:
sys.stderr.write('.')
test.run()
clock_end = clockfn() - clock_start
log('%.6f' % clock_end)
except Exception, e:
log('failed %s' % str(e))
continue
clock_total += clock_end
log('')
log('Result: %.6f' % clock_total)
log('')
try:
reply = raw_input(
'Do you want to send benchmark to gist.github.com (Y/n) : ')
except EOFError:
sys.exit(0)
if reply.lower().strip() in ('', 'y'):
print 'Please wait while sending the benchmark...'
try:
import requests
except ImportError:
print "`requests` module not found, no benchmark posted."
sys.exit(1)
payload = {
'public': True, 'files': {
'benchmark.txt': {
'content': '\n'.join(report)}}}
r = requests.post('https://api.github.com/gists', data=json.dumps(payload))
print
print
print 'REPORT posted at {0}'.format(r.json['html_url'])
print
print
else:
print 'No benchmark posted.'
|