This file is indexed.

/usr/share/pyshared/pymt/tools/benchmark.py is in python-pymt 0.5.1-0ubuntu3.

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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
'''
Benchmark for PyMT Framework
'''

benchmark_version = '1'

import gc
import pymt
import sys
import os
import OpenGL
import time
from OpenGL.GL import *
from random import randint, random
from pymt import *
from pymt.graphics import *
from time import clock, time, ctime

clockfn = time
if sys.platform == 'win32':
    clockfn = clock

try:
    window_size = getWindow().size
except:
    window_size = MTWindow().size

class bench_core_label:
    '''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(label=x))


class bench_widget_creation:
    '''Widget: creation (10000 MTWidget)'''
    def run(self):
        o = []
        for x in xrange(10000):
            o.append(MTWidget())

class bench_widget_dispatch:
    '''Widget: event dispatch (1000 on_update in 10*1000 MTWidget)'''
    def __init__(self):
        root = MTWidget()
        for x in xrange(10):
            parent = MTWidget()
            for y in xrange(1000):
                parent.add_widget(MTWidget())
            root.add_widget(parent)
        self.root = root
    def run(self):
        root = self.root
        for x in xrange(1000):
            root.dispatch_event('on_update')

class bench_graphx_line:
    '''Graphx: draw lines (5000 x/y) 1000 times'''
    def __init__(self):
        lines = []
        w, h = window_size
        for x in xrange(5000):
            lines.extend([random() * w, random() * h])
        self.lines = lines
    def run(self):
        lines = self.lines
        for x in xrange(1000):
            drawLine(lines)

class bench_graphics_line:
    '''Graphics: draw lines (5000 x/y) 1000 times'''
    def __init__(self):
        w, h = window_size
        self.canvas = Canvas()
        line = self.canvas.line()
        for x in xrange(5000):
            line.points += [random() * w, random() * h]
    def run(self):
        canvas = self.canvas
        for x in xrange(1000):
            canvas.draw()


class bench_graphx_rectangle:
    '''Graphx: draw rectangle (5000 rect) 1000 times'''
    def __init__(self):
        rects = []
        w, h = window_size
        for x in xrange(5000):
            rects.append(((random() * w, random() * h), (random() * w, random() * h)))
        self.rects = rects
    def run(self):
        rects = self.rects
        for x in xrange(1000):
            for pos, size in rects:
                drawRectangle(pos=pos, size=size)

class bench_graphics_rectangle:
    '''Graphics: draw rectangle (5000 rect) 1000 times'''
    def __init__(self):
        rects = []
        w, h = window_size
        canvas = Canvas()
        for x in xrange(5000):
            canvas.rectangle(random() * w, random() * h, random() * w, random() * h)
        self.canvas = canvas
    def run(self):
        canvas = self.canvas
        for x in xrange(1000):
            canvas.draw()

class bench_graphics_rectanglemesh:
    '''Graphics: draw rectangle in same mesh (5000 rect) 1000 times'''
    def __init__(self):
        rects = []
        w, h = window_size
        canvas = Canvas()
        mesh = canvas.graphicElement(format='vv', type='quads')
        vertex = []
        for x in xrange(50000):
            vertex.extend([random() * w, random() * h, random() * w, random() * h])
        mesh.data_v = vertex
        self.canvas = canvas
    def run(self):
        canvas = self.canvas
        for x in xrange(1000):
            canvas.draw()

class bench_graphx_roundedrectangle:
    '''Graphx: draw rounded rectangle (5000 rect) 1000 times'''
    def __init__(self):
        rects = []
        w, h = window_size
        for x in xrange(5000):
            rects.append(((random() * w, random() * h), (random() * w, random() * h)))
        self.rects = rects
    def run(self):
        rects = self.rects
        for x in xrange(1000):
            for pos, size in rects:
                drawRoundedRectangle(pos=pos, size=size)


class bench_graphics_roundedrectangle:
    '''Graphics: draw rounded rectangle (5000 rect) 1000 times'''
    def __init__(self):
        rects = []
        w, h = window_size
        canvas = Canvas()
        for x in xrange(5000):
            canvas.roundedRectangle(random() * w, random() * h, random() * w, random() * h)
        self.canvas = canvas
    def run(self):
        canvas = self.canvas
        for x in xrange(1000):
            canvas.draw()

class bench_graphx_paintline:
    '''Graphx: paint line (5000 x/y) 1000 times'''
    def __init__(self):
        lines = []
        w, h = window_size
        for x in xrange(500):
            lines.extend([random() * w, random() * h])
        self.lines = lines
        set_brush(os.path.join(pymt_data_dir, 'particle.png'))
    def run(self):
        lines = self.lines
        for x in xrange(100):
            paintLine(lines)

class bench_graphics_paintline:
    '''Graphics: paint lines (5000 x/y) 1000 times'''
    def __init__(self):
        w, h = window_size
        self.canvas = Canvas()
        texture = Image(os.path.join(pymt_data_dir, 'particle.png')).texture
        line = self.canvas.point(type='line_strip', texture=texture)
        for x in xrange(500):
            line.points += [random() * w, random() * h]
    def run(self):
        canvas = self.canvas
        for x in xrange(100):
            canvas.draw()


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('PyMT 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)
    try:
        log('PyMT Version    : %s' % pymt.__version__)
    except:
        log('PyMT Version    : unknown (too old)')
    log('Install path    : %s' % os.path.dirname(pymt.__file__))
    log('Install date    : %s' % ctime(os.path.getctime(pymt.__file__)))

    log('')
    log('OpenGL informations')
    log('-------------------')

    log('PyOpenGL Version: %s' % OpenGL.__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:
    getWindow().close()
except:
    pass

try:
    reply = raw_input('Do you want to send benchmark to paste.pocoo.org (Y/n) : ')
except EOFError:
    sys.exit(0)

if reply.lower().strip() in ('', 'y'):
    print 'Please wait while sending the benchmark...'

    from xmlrpclib import ServerProxy
    s = ServerProxy('http://paste.pocoo.org/xmlrpc/')
    r = s.pastes.newPaste('text', '\n'.join(report))

    print
    print
    print 'REPORT posted at http://paste.pocoo.org/show/%s/' % r
    print
    print
else:
    print 'No benchmark posted.'