#!/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))