Created
September 2, 2010 13:05
-
-
Save bga/562258 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
@hint | |
@see https://wiki.mozilla.org/Audio_Data_API | |
@see http://www.opensource.apple.com/source/WebCore/WebCore-737.5/html/canvas/ | |
@see https://cvs.khronos.org/svn/repos/registry/trunk/public/webgl/doc/spec/TypedArray-spec.html | |
Array.U32 = $G.Uint32Array || $G.WebGLUnsignedIntArray || $G.CanvasUnsignedIntArray || Array; | |
Array.U16 = $G.Uint16Array || $G.WebGLUnsignedShortArray || $G.CanvasUnsignedShortArray || Array; | |
Array.U8 = $G.Uint8Array || $G.WebGLUnsignedByteArray || $G.CanvasUnsignedByteArray || Array; | |
Array.S32 = $G.Int32Array || $G.WebGLIntArray || $G.CanvasIntArray || Array; | |
Array.S16 = $G.Int16Array || $G.WebGLShortArray || $G.CanvasShortArray || Array; | |
Array.S8 = $G.Int8Array || $G.WebGLByteArray || $G.CanvasByteArray || Array; | |
Array.F32 = $G.Float32Array || $G.WebGLFloatArray || $G.CanvasFloatArray || Array; | |
Array.F64 = $G.Float64Array || Array; | |
*/ | |
var $G = this | |
, Float32Array = $G.Float32Array || $G.WebGLFloatArray | |
, len = 1000 | |
, a = new Array(len) | |
, b = new Array(len) | |
, typedA = new Float32Array(len) | |
, typedB = new Float32Array(len) | |
; | |
var _blur = function(a, b, n) | |
{ | |
var lenSub1 = len - 1; | |
var i = n; while(i--) | |
{ | |
var j = lenSub1; while(--j) | |
b[j] = (a[j - 1] + a[j] + a[j + 1])/3; | |
var j = lenSub1; while(--j) | |
a[j] = (b[j - 1] + b[j] + b[j + 1])/3; | |
} | |
} | |
_speedTest( | |
[ | |
function(n) | |
{ | |
_blur(typedA, typedB, n); | |
}, | |
function(n) | |
{ | |
_blur(a, b, n); | |
} | |
], | |
5000 | |
); | |
/* | |
chrome 7 5000 | |
0: 3190 ms | |
1: 12528 ms | |
ff4 5000 | |
0: 668 ms | |
1: 10517 ms | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment