mirror of
https://github.com/servo/servo.git
synced 2025-08-06 22:15:33 +01:00
auto merge of #950 : jdm/servo/matrixmath, r=metajack
This commit is contained in:
commit
b77c3eaaa0
2 changed files with 62 additions and 25 deletions
|
@ -1,14 +1,10 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<iframe sandbox="allow-scripts" src="test_sandboxed_iframe.html"
|
<iframe sandbox="allow-scripts" src="test_sandboxed_iframe.html"
|
||||||
style="display:block; border: 1px; width: 400px; height: 400px"
|
style="display:block; border: 1px; width: 400px; height: 400px">
|
||||||
frameborder="yes"
|
</iframe>
|
||||||
scrolling="yes"></iframe>
|
|
||||||
hiiiiiiiii
|
|
||||||
<iframe sandbox="allow-scripts" src="test_sandboxed_iframe.html"
|
<iframe sandbox="allow-scripts" src="test_sandboxed_iframe.html"
|
||||||
style="display:block; border: 1px; width: 400px; height: 400px"
|
style="display:block; border: 1px; width: 400px; height: 400px">
|
||||||
frameborder="yes"
|
</iframe>
|
||||||
scrolling="yes"></iframe>
|
|
||||||
byeeeeeeeeeeee
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -1,24 +1,65 @@
|
||||||
<html>
|
<html>
|
||||||
<body>
|
<body>
|
||||||
<script>
|
<script>
|
||||||
var a = 1;
|
function Matrix(ary) {
|
||||||
var b = 1;
|
this.mtx = ary
|
||||||
var c = 2;
|
this.height = ary.length;
|
||||||
var step = 1;
|
this.width = ary[0].length;
|
||||||
window.alert(Date.now());
|
}
|
||||||
var next = new Date();
|
|
||||||
window.alert(next);
|
Matrix.prototype.toString = function() {
|
||||||
while (true) {
|
var s = []
|
||||||
if ((new Date()) >= next) {
|
for (var i = 0; i < this.mtx.length; i++)
|
||||||
window.alert("step " + step + ": " + c);
|
s.push( this.mtx[i].join(",") );
|
||||||
a = b;
|
return s.join("\n");
|
||||||
b = c;
|
}
|
||||||
c = a + b;
|
|
||||||
step++;
|
Matrix.prototype.mult = function(other) {
|
||||||
next = new Date(Date.now() + 500);
|
if (this.width != other.height) {
|
||||||
}
|
throw "error: incompatible sizes";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var result = [];
|
||||||
|
for (var i = 0; i < this.height; i++) {
|
||||||
|
result[i] = [];
|
||||||
|
for (var j = 0; j < other.width; j++) {
|
||||||
|
var sum = 0;
|
||||||
|
for (var k = 0; k < this.width; k++) {
|
||||||
|
sum += this.mtx[i][k] * other.mtx[k][j];
|
||||||
|
}
|
||||||
|
result[i][j] = sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new Matrix(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
function run() {
|
||||||
|
var now = new Date();
|
||||||
|
var div = document.getElementsByTagName('div')[0];
|
||||||
|
var elems = [];
|
||||||
|
for (var i = 0; i < 900; i++) {
|
||||||
|
elems.push(i);
|
||||||
|
}
|
||||||
|
var outer = [];
|
||||||
|
for (var i = 0; i < 900; i++) {
|
||||||
|
outer.push(elems);
|
||||||
|
}
|
||||||
|
var a = new Matrix(outer);
|
||||||
|
var b = new Matrix(outer);
|
||||||
|
var result = a.mult(b);
|
||||||
|
var time = (new Date()) - now;
|
||||||
|
var text = document.createTextNode(time.toString() + 'ms');
|
||||||
|
var para = document.createElement('p');
|
||||||
|
para.appendChild(text);
|
||||||
|
div.appendChild(para);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTimeout(function forever() {
|
||||||
|
run();
|
||||||
|
setTimeout(forever, 3000);
|
||||||
|
}, 0);
|
||||||
</script>
|
</script>
|
||||||
hi there
|
<p>Time required to multiply two 900x900 matrices:</p>
|
||||||
|
<div></div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue