-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.html
144 lines (137 loc) · 10.6 KB
/
benchmark.html
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
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>http benchmark</title>
<link rel="stylesheet" href="https://unpkg.com/awsm.css/dist/awsm.min.css">
<link href="https://fonts.googleapis.com/css?family=PT Sans|PT Serif:400,400i,700,700i&subset=cyrillic" rel="stylesheet">
<style>
#dynamic{
background-color: #eff;
width: 600px;
height: 240px;
}
#dynamic img{
float:left;
}
input[type="button"] {
display: inline-block;
*display: inline;
zoom: 1;
padding: 6px 20px;
margin: 0;
cursor: pointer;
border: 1px solid #bbb;
overflow: visible;
font: bold 13px arial, helvetica, sans-serif;
text-decoration: none;
white-space: nowrap;
color: #555;
background-color: #ddd;
background-image: linear-gradient(rgba(255,255,255,1), rgba(255,255,255,0)), url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAABkCAMAAAD0WI85AAADAFBMVEX///8AAACAgIDr6+tqamp5eXnv7++1tbW/v79ERES+vr6VlZXk5OSwsLA6OjphYWHj4+PCwsLw8PDi4uK3t7dISEhAQECSkpKIiIh2dnY9PT0uLi5/f39NTU1ZWVnq6uqgoKCKiorS0tJQUFDAwMDIyMihoaH8/PylpaXn5+dmZmbo6Oiurq7Nzc2UlJT6+vqqqqqoqKgyMjL29vbJycnl5eUxMTHY2NhLS0tdXV339/dfX1/t7e2kpKTR0dGGhobh4eGjo6MwMDBlZWUkJCRjY2PQ0NCfn5/09PSbm5vDw8PFxcW5ubl+fn7e3t5VVVXm5ubg4OBsbGx4eHhnZ2ff399BQUFiYmKPj4/z8/N0dHS9vb2dnZ01NTXU1NRMTEwJCQkRERGYmJjV1dUoKCiioqI8PDzp6enT09OsrKwTExMYGBjd3d0VFRVoaGi2trbLy8vPz8+FhYWMjIyEhIQ+Pj6Hh4dubm7X19dtbW2xsbHOzs56enr7+/uCgoICAgJgYGBycnJvb2+RkZHc3Ny7u7v9/f0SEhJXV1fHx8eysrJCQkKLi4vb29upqamtra1DQ0NcXFxkZGTMzMxzc3OcnJyZmZnZ2dnGxsaDg4Pu7u6np6fx8fGmpqaJiYny8vK8vLzBwcEEBAQlJSV9fX1wcHBxcXEODg7W1tZ8fHzKysqNjY20tLRJSUmWlpazs7NOTk5FRUV1dXX5+flSUlJ7e3vExMQ4ODhHR0dbW1tWVlY3NzcqKio0NDQPDw8rKysaGhocHBwdHR0nJyeenp74+PgiIiImJiZ3d3deXl7a2tqampoHBwdUVFSBgYG4uLhpaWkhISEXFxc/Pz9ra2s7OzsMDAxTU1M5OTkICAgjIyOXl5cbGxsfHx8sLCy6urqrq6sKCgoLCwtRUVFYWFhaWlpGRkYpKSkNDQ0zMzM2NjaQkJAGBgZKSkqOjo4ZGRkFBQUWFhYgICAQEBAtLS3+/v719fUvLy9PT08BAQGTk5Ps7OwDAwMUFBQeHh6vr6/zapmXAAABAHRSTlMFCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg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ix bleeding */
border-radius: 3px;
box-shadow: 0 1px 0 rgba(0, 0, 0, .3),
0 2px 2px -1px rgba(0, 0, 0, .5),
0 1px 0 rgba(255, 255, 255, .3) inset;
text-shadow: 0 1px 0 rgba(255,255,255, .9);
user-select: none;
padding: 4px 12px;
}
input[type="button"]:hover {
background-color: #eee;
color: #555;
}
input[type="button"]:active {
background: #e9e9e9;
position: relative;
top: 1px;
text-shadow: none;
box-shadow: 0 1px 1px rgba(0, 0, 0, .3) inset;
}
iframe {
margin: 15px;
}
</style>
</head>
<body>
<header>
<p>shitty http benchmark</p>
<p>backend: VPS 2000GHz/512Mb, go1.8.1 (net/http, quic-go)</p>
<h5>tl;dr:</h5>
<ul>
<li>http2 is faster when a lot of files are downloaded from a single domain</li>
<li>QUIC is faster when packet loss is persistent</li>
<li>nothing beats sharding</li>
</ul>
</header>
<main>
<h3>Case 1: 1000 files async</h3>
<p>1000 png images, fetch api</p>
<input type="button" value="HTTP/1.1" onclick="requestImgs('http', '8080', 'cross.png', 1000)">
<input type="button" value="HTTP/1.1 TLS" onclick="requestImgs('https', '8081', 'cross.png', 1000)">
<input type="button" value="HTTP/2" onclick="requestImgs('https', '8082', 'cross.png', 1000)">
<input type="button" value="QUIC" onclick="requestImgs('https', '8083', 'cross.png', 1000)">
<p id="timer">Load time:</p>
<div id="dynamic"></div>
<h3>Case 2: Big file</h3>
<p>10M file, fetch api</p>
<input type="button" value="HTTP/1.1" onclick="requestImgs('http', '8080', 'big_file', 1)">
<input type="button" value="HTTP/1.1 TLS" onclick="requestImgs('https', '8081', 'big_file', 1)">
<input type="button" value="HTTP/2" onclick="requestImgs('https', '8082', 'big_file', 1)">
<input type="button" value="QUIC" onclick="requestImgs('https', '8083', 'big_file', 1)">
<h3>Case 3: 1000 Crosses sync</h3>
<p>1000 png images in iframe sync load</p>
<input type="button" value="HTTP/1.1" onclick="renderFrame('http://vps.nikitin.su:8080/demo')">
<input type="button" value="HTTP/1.1 + sharding x10" onclick="renderFrame('http://vps.nikitin.su:8080/demo_sharding')">
<input type="button" value="HTTP/1.1 TLS" onclick="renderFrame('https://vps.nikitin.su:8081/demo')">
<input type="button" value="HTTP/2" onclick="renderFrame('https://vps.nikitin.su:8082/demo')">
<input type="button" value="QUIC" onclick="renderFrame('https://vps.nikitin.su:8083/demo')">
<div id="for_iframe"></div>
</main>
<script>
function updateTimer(timer, time){
timer.innerHTML = "Load time: " + time + "ms.";
}
function renderImageFromBLOB(container,blob){
var img = document.createElement("img");
img.style.width = "12px";
img.onload = function(){
updateTimer(timerText, performance.now() - start);
}
img.onerror = function(){
updateTimer(timerText, performance.now() - start);
}
container.appendChild(img);
img.src = URL.createObjectURL(blob);
}
var timerText = document.querySelector('p#timer');
var imageContainer = document.querySelector('div#dynamic');
var iframeContainer = document.querySelector('div#for_iframe');
var start = performance.now();
var hostname = window.location.hostname;
function requestImgs(protocol, port, filename, count){
start = performance.now();
imageContainer.innerHTML = "";
for (i = 0; i < count; i++) {
fetch(protocol +'://' + hostname + ':' + port + '/static/' + filename + '?' + Math.random()).then(function(response) {
return response.blob();
}).then(function(myBlob) {
renderImageFromBLOB(imageContainer, myBlob)
});
}
}
function renderFrame(location) {
var iframeLoadStart = performance.now();
var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", location);
ifrm.onload = function() {
this.insertAdjacentHTML('afterend',"<pre>↑ loaded in "+ (performance.now() - iframeLoadStart) + "ms after click</pre>")
window.scrollTo(0,document.body.scrollHeight);
}
iframeContainer.appendChild(ifrm);
}
</script>
</body>
</html>