Skip to content

Commit 35f5f91

Browse files
authored
Merge pull request #78 from StanFromIreland/speed.pypy.org-embedding
Generate a page with baseline comparison for speed.pypy.org
2 parents 7121c01 + 636a4e7 commit 35f5f91

4 files changed

Lines changed: 117 additions & 34 deletions

File tree

codespeed/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
]
1515

1616
urlpatterns += [
17+
re_path(r'^embed/comparison/$', views.embed_comparison, name='embed-comparison'),
1718
re_path(r'^historical/json/$', views.gethistoricaldata, name='gethistoricaldata'),
1819
re_path(r'^reports/$', views.reports, name='reports'),
1920
re_path(r'^changes/$', views.changes, name='changes'),

codespeed/views.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
from django.shortcuts import get_object_or_404, render
1717
from django.views.decorators.http import require_GET, require_POST
1818
from django.views.decorators.csrf import csrf_exempt
19+
from django.views.decorators.clickjacking import xframe_options_exempt
1920
from django.views.generic.base import TemplateView
2021

2122
from .auth import basic_auth_required
@@ -93,6 +94,24 @@ def get_context_data(self, **kwargs):
9394
return context
9495

9596

97+
@require_GET
98+
@xframe_options_exempt
99+
def embed_comparison(request):
100+
"""Frame-exempt page rendering only the baseline-comparison
101+
for embedding on pypy.org"""
102+
context = {}
103+
try:
104+
context['baseline'] = Executable.objects.get(
105+
name=settings.DEF_BASELINES[0]['executable'])
106+
def_name = settings.DEF_EXECUTABLES[0]['name']
107+
def_project = Project.objects.get(name=settings.DEF_EXECUTABLES[0]['project'])
108+
context['default_exe'] = Executable.objects.get(
109+
name=def_name, project=def_project)
110+
except Exception as e:
111+
logger.error('embed_comparison: %s', e)
112+
return render(request, 'embed_comparison.html', context)
113+
114+
96115
@require_GET
97116
def gethistoricaldata(request):
98117
data = {'results': {}, 'benchmarks': []}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
{% load static %}
2+
<!DOCTYPE html>
3+
<html>
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<title>PyPy vs CPython benchmark comparison</title>
8+
<style>
9+
html, body { margin: 0; padding: 0; background: transparent; }
10+
#baseline-comparison-plot {
11+
position: relative;
12+
width: 100%;
13+
height: 480px;
14+
font-family: sans-serif;
15+
}
16+
</style>
17+
</head>
18+
<body>
19+
<div id="baseline-comparison-plot"></div>
20+
21+
<script type="text/javascript" src="{% static 'js/jquery-1.12.3.min.js' %}"></script>
22+
<script type="text/javascript" src="{% static 'js/chart.umd.min.js' %}"></script>
23+
<script type="text/javascript">
24+
Chart.Tooltip.positioners.cursor = function(_items, eventPosition) {
25+
return {x: eventPosition.x, y: eventPosition.y};
26+
};
27+
28+
function renderplot(data) {
29+
var wrap = document.getElementById('baseline-comparison-plot');
30+
if (data === null || data.length === 0 ||
31+
typeof data === 'string' || data instanceof String) {
32+
wrap.innerHTML = 'Error retrieving data';
33+
return;
34+
}
35+
36+
var benchmarks = [], latestValues = [], baselineValues = [];
37+
var tagged_data = [];
38+
for (var i in data['tagged_revs']) { tagged_data[i] = []; }
39+
40+
for (var bench in data['benchmarks']) {
41+
var benchname = data['benchmarks'][bench];
42+
var add_to_tagged_data = true;
43+
for (var i in data['tagged_revs']) {
44+
var rev = data['tagged_revs'][i];
45+
if (data['results'][benchname][rev] === 0) { add_to_tagged_data = false; break; }
46+
tagged_data[i].push(data['results'][benchname][rev] / data['results'][benchname][data['baseline']]);
47+
}
48+
if (!add_to_tagged_data) { continue; }
49+
benchmarks.push(benchname);
50+
var rel = data['results'][benchname]['latest'] / data['results'][benchname][data['baseline']];
51+
latestValues.push(rel);
52+
baselineValues.push(1.0);
53+
}
54+
55+
var canvas1 = document.createElement('canvas');
56+
wrap.appendChild(canvas1);
57+
new Chart(canvas1, {
58+
type: 'bar',
59+
data: {
60+
labels: benchmarks,
61+
datasets: [
62+
{label: 'latest {{ default_exe }}', data: latestValues, backgroundColor: '#4e79a7'},
63+
{label: data['baseline'], data: baselineValues, type: 'line',
64+
borderColor: '#f28e2b', backgroundColor: 'transparent',
65+
pointRadius: 0, borderWidth: 2, fill: false}
66+
]
67+
},
68+
options: {
69+
animation: false,
70+
responsive: true,
71+
maintainAspectRatio: false,
72+
plugins: {
73+
tooltip: {position: 'cursor'}
74+
},
75+
scales: {
76+
x: {ticks: {maxRotation: 70, minRotation: 70, autoSkip: false, font: {size: 11}}},
77+
y: {min: 0, max: 2.0, ticks: {callback: function(v) { return v.toFixed(2); }}}
78+
}
79+
}
80+
});
81+
}
82+
83+
$(function() {
84+
$.getJSON("{% url 'gethistoricaldata' %}", renderplot);
85+
});
86+
</script>
87+
</body>
88+
</html>

speed_pypy/templates/home.html

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ <h2>Comparison</h2>
2929
{% if show_historical %}
3030
<div id="historical">
3131
<h3>How fast is {{ default_exe.project }}?</h3>
32-
<div id="baseline-comparison-plot" style="position:relative;height:400px;"></div>
32+
<iframe src="{% url 'embed-comparison' %}"
33+
title="{{ default_exe.project }} ({{ default_exe }}) vs {{ baseline }} benchmark comparison"
34+
style="border:0;width:100%;height:400px"
35+
loading="lazy"></iframe>
3336
<p class="plot-caption">Plot 1: The above plot represents {{ default_exe.project }} ({{ default_exe }}) benchmark times normalized to {{ baseline }}. Smaller is better.</p>
3437
<p>It depends greatly on the type of task being performed. The geometric average of all benchmarks is <span id="geomean"></span> or <strong id="geofaster"></strong> times <em>faster</em> than {{ baseline }}</p>
3538

@@ -68,15 +71,15 @@ <h3>How has PyPy performance evolved over time?</h3>
6871

6972
function renderplot(data) {
7073
if (data === null || data.length === 0) {
71-
$("#baseline-comparison-plot").html(getLoadText('Error retrieving data', 0));
74+
$("#historical-plot").html(getLoadText('Error retrieving data', 0));
7275
return;
7376
}
7477
if (typeof data === 'string' || data instanceof String) {
75-
$("#baseline-comparison-plot").html(getLoadText('Error retrieving data ' + data, 0));
78+
$("#historical-plot").html(getLoadText('Error retrieving data ' + data, 0));
7679
return;
7780
}
7881

79-
var benchmarks = [], latestValues = [], baselineValues = [];
82+
var latestValues = [];
8083
var trunk_geomean = 1;
8184
var tagged_data = [];
8285
for (var i in data['tagged_revs']) { tagged_data[i] = []; }
@@ -90,45 +93,17 @@ <h3>How has PyPy performance evolved over time?</h3>
9093
tagged_data[i].push(data['results'][benchname][rev] / data['results'][benchname][data['baseline']]);
9194
}
9295
if (!add_to_tagged_data) { continue; }
93-
benchmarks.push(benchname);
9496
var rel = data['results'][benchname]['latest'] / data['results'][benchname][data['baseline']];
9597
latestValues.push(rel);
96-
baselineValues.push(1.0);
9798
if (rel > 0 && !isNaN(rel)) { trunk_geomean *= rel; }
9899
}
99100

100101
trunk_geomean = Math.pow(trunk_geomean, 1 / latestValues.length);
101102
$('#geomean').html(trunk_geomean.toFixed(2));
102103
$('#geofaster').html((1 / trunk_geomean).toFixed(1));
103104

104-
// Plot 1: per-benchmark normalized comparison
105-
var wrap1 = document.getElementById('baseline-comparison-plot');
106-
var canvas1 = document.createElement('canvas');
107-
wrap1.appendChild(canvas1);
108-
new Chart(canvas1, {
109-
type: 'bar',
110-
data: {
111-
labels: benchmarks,
112-
datasets: [
113-
{label: 'latest {{ default_exe }}', data: latestValues, backgroundColor: '#4e79a7'},
114-
{label: data['baseline'], data: baselineValues, type: 'line',
115-
borderColor: '#f28e2b', backgroundColor: 'transparent',
116-
pointRadius: 0, borderWidth: 2, fill: false}
117-
]
118-
},
119-
options: {
120-
animation: false,
121-
responsive: true,
122-
maintainAspectRatio: false,
123-
plugins: {
124-
tooltip: {position: 'cursor'}
125-
},
126-
scales: {
127-
x: {ticks: {maxRotation: 70, minRotation: 70, autoSkip: false, font: {size: 11}}},
128-
y: {min: 0, max: 2.0, ticks: {callback: function(v) { return v.toFixed(2); }}}
129-
}
130-
}
131-
});
105+
// Plot 1 (per-benchmark normalized comparison) is rendered by the
106+
// embed_comparison page shown in the iframe above.
132107

133108
// Plot 2: geomean speedup over tagged revisions
134109
var geomeans = [1.0];

0 commit comments

Comments
 (0)