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
|
#!/usr/bin/python
# This script intends to operate caskbench in a manner that
# will replicate the results of canvas_perf.js, but in C++.
#
# ref:
# http://flashcanvas.net/examples/dl.dropbox.com/u/1865210/mindcat/canvas_perf.html
from __future__ import absolute_import, print_function, unicode_literals
from exceptions import Exception
from subprocess import (Popen, PIPE)
import json
CASKBENCH = 'src/caskbench'
perfdefs = [
[ "hline", 1000, 30, ["hline"] ],
[ "vline", 1000, 15, ["vline"] ],
[ "line", 1000, 6, ["line"] ],
[ "rect", 1000, 5, ["rect", "-f", "none"] ],
[ "fill_rect", 500, 5, ["rect", "-f", "solid"] ],
[ "lines", 1000, 8, ["multi_line"] ],
[ "arc", 1000, 4, ["circle", "-f", "none"] ],
[ "fill_arc", 1000, 7, ["circle", "-f", "solid"] ],
[ "bezier", 1000, 3, ["cubic"] ],
[ "fill_bezier", 1000, 4, ["cubic", "-f", "solid"] ],
[ "quad", 1000, 4, ["quadratic"] ],
[ "curves", 50, 5, ["curves", "-f", "none"] ],
[ "fill_curves", 50, 8, ["curves", "-f", "solid"] ],
[ "stroke_star", 1000, 7, ["star", "-f", "none"] ],
[ "fill_star", 1000, 12, ["star", "-f", "solid"] ],
[ "transform", 10, 0.2, ["transform"] ],
[ "image", 100, 0.3, ["image"] ],
[ "image_scale", 100, 0.8, ["image_scale"] ],
[ "image_rotate", 15, 0.3, ["image_rotate"] ],
[ "linear_gradient", 100, 2, ["linear_gradient"] ],
[ "radial_gradient", 100, 0.3, ["radial_gradient"] ],
[ "text", 100, 0.6, ["text"] ],
[ "clip", 100, 0.8, ["clip"] ]
]
class ReturnCode(Exception):
def __init__(self, code, errors=None):
self.code = code
if type(errors) in (list, tuple):
self.errors = errors
else:
self.errors = [errors]
def __str__(self):
text = '\n'.join(self.errors)
return "%s returned error code %d" %(text, self.code)
def execute(command):
p = Popen(command, shell=False, stdout=PIPE, stderr=PIPE)
output = p.stdout.read()
if p.returncode:
dbg("Error (%d) encountered in execution" %(p.returncode))
raise ReturnCode(p.returncode, p.stderr.readlines())
return output
results = []
iterations = 100
for testcase in perfdefs:
cmd = [ CASKBENCH,
'-D', 'skia',
'-w', '480',
'-h', '480',
'-i', str(iterations),
'-s', str(testcase[1]),
'-j',
'-o', '/tmp/output.json',
'-t', 'egl',
'--deferred-rendering',
]
cmd += testcase[3]
print(' '.join(cmd))
json_output = execute(cmd)
print(json_output)
with open('/tmp/output.json') as file:
result = json.load(file)[0]
value = testcase[1] / (result["average run time (s)"]*1000)
ratio = value / testcase[2]
results.append({
'testcase': testcase[0],
'ratio': ratio
})
# Calculate the score
total = 0
for result in results:
print("%s: %3.2f" %(result['testcase'], result['ratio']))
total += 1.0 / result['ratio']
if total > 0:
score = (len(perfdefs) / total)
print("Total Score: %3.2f" %(score))
|