Skip to content

Commit

Permalink
Updates to benchmarks.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bebenita committed Nov 12, 2011
1 parent ae1db56 commit a4f39aa
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 50 deletions.
94 changes: 52 additions & 42 deletions Demo/benchmarks.html
Expand Up @@ -74,8 +74,10 @@
fn();
}
var elapsed = Date.now() - start;
var rate = (count / elapsed) * 1000;
var msg = name + " - Total: " + elapsed + " ms, Count: " + count + ", Rate: " + rate.toFixed(2) + " op/s";
var rateSecond = (count / elapsed) * 1000;
var rate2 = (elapsed / count);
var msg = name + " - Total: " + elapsed + " ms, Count: " + count +
", Rate: " + rateSecond.toFixed(2) + " op/s, " + rate2.toFixed(3) + " ms/op";
console.log(msg);

$("#results").append("<p>" + msg + "</p>");
Expand All @@ -86,59 +88,67 @@

var benchmarks = [];

var c1 = new WebGLCanvas(document.getElementById('canvas-1'), size);

var buffer = new Uint8Array(size.w * size.h);
for (var i = 0; i < buffer.length; i++) {
buffer[i] = i;
}

benchmarks.push(function() {
time("Fill Texture", function () {
c1.texture.fill(buffer);
}, 10000);
});
var samples = 5000;

benchmarks.push(function() {
time("Draw Scene", function () {
c1.drawScene();
}, 10000);
});
if (true) {
var c1 = new WebGLCanvas(document.getElementById('canvas-1'), size);
benchmarks.push(function() {
time("Fill Texture", function () {
c1.texture.fill(buffer);
}, samples);
});

benchmarks.push(function() {
time("Draw Scene", function () {
c1.drawScene();
}, samples);
});

benchmarks.push(function() {
time("Fill Texture + Draw Scene", function () {
c1.texture.fill(buffer);
c1.drawScene();
}, samples);
});
}

benchmarks.push(function() {
time("Fill Texture + Draw Scene", function () {
c1.texture.fill(buffer);
c1.drawScene();
}, 10000);
});

var c2 = new YUVWebGLCanvas(document.getElementById('canvas-2'), size);
var chroma = new Uint8Array((size.w >>> 1) * (size.h >>> 1));
for (var i = 0; i < chroma.length; i++) {
chroma[i] = i;
}

benchmarks.push(function() {
time("YUV Fill Texture", function () {
c2.YTexture.fill(buffer);
c2.UTexture.fill(chroma);
c2.VTexture.fill(chroma);
}, 10000);
});

benchmarks.push(function() {
time("YUV Draw Scene", function () {
c2.drawScene();
}, 10000);
});

benchmarks.push(function() {
time("YUV Fill Texture + Draw Scene", function () {
c2.YTexture.fill(buffer);
c2.UTexture.fill(chroma);
c2.VTexture.fill(chroma);
c2.drawScene();
}, 10000);
});
if (true) {
var c2 = new YUVWebGLCanvas(document.getElementById('canvas-2'), size);
benchmarks.push(function() {
time("YUV Fill Texture", function () {
c2.YTexture.fill(buffer);
c2.UTexture.fill(chroma);
c2.VTexture.fill(chroma);
}, samples);
});

benchmarks.push(function() {
time("YUV Draw Scene", function () {
c2.drawScene();
}, samples);
});

benchmarks.push(function() {
time("YUV Fill Texture + Draw Scene", function () {
c2.YTexture.fill(buffer);
c2.UTexture.fill(chroma);
c2.VTexture.fill(chroma);
c2.drawScene();
}, samples);
});
}

var benchmarkIndex = 0;
window.addEventListener("message", function() {
Expand Down
21 changes: 13 additions & 8 deletions Demo/canvas.js
Expand Up @@ -308,10 +308,6 @@ var WebGLCanvas = (function () {
if (!this.gl) {
error("Unable to initialize WebGL. Your browser may not support it.");
}
var gl = this.gl;
gl.enable(gl.DEPTH_TEST);
gl.depthFunc(gl.LEQUAL);

if (this.glNames) {
return;
}
Expand Down Expand Up @@ -340,10 +336,7 @@ var WebGLCanvas = (function () {
this.texture.bind(0, this.program, "texture");
},
drawScene: function() {
var gl = this.gl;
// Clear the canvas before we start drawing on it.
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
this.gl.drawArrays(this.gl.TRIANGLE_STRIP, 0, 4);
}
};
return constructor;
Expand Down Expand Up @@ -386,6 +379,18 @@ var YUVWebGLCanvas = (function () {
"}"
]));

var fragmentShaderScriptSimple = Script.createFromSource("x-shader/x-fragment", text([
"precision highp float;",
"varying highp vec2 vTextureCoord;",
"uniform sampler2D YTexture;",
"uniform sampler2D UTexture;",
"uniform sampler2D VTexture;",

"void main(void) {",
" gl_FragColor = texture2D(YTexture, vTextureCoord);",
"}"
]));

var fragmentShaderScript = Script.createFromSource("x-shader/x-fragment", text([
"precision highp float;",
"varying highp vec2 vTextureCoord;",
Expand Down

0 comments on commit a4f39aa

Please sign in to comment.