Editing typed arrays This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Test the performance of typed arrays vs normal arrays Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <script> var N = 100000; var arr = new Array(N), i8arr = new Int8Array(N), ui8arr = new Uint8Array(N), i16arr = new Int16Array(N), ui16arr = new Uint16Array(N), i32arr = new Int32Array(N), ui32arr = new Uint32Array(N), f32arr = new Float32Array(N), f64arr = new Float64Array(N); var i; for (i = 0; i < N; i++) { arr[i] = i; i8arr[i] = i; ui8arr[i] = i; i16arr[i] = i; ui16arr[i] = i; i32arr[i] = i; ui32arr[i] = i; f32arr[i] = i; f64arr[i] = i; } </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code var i; for (i = 0; i < N; i++) { arr[i] = arr[i] * arr[i]; } Test 2 Title Async (check if this is an asynchronous test) Code var i; for (i = 0; i < N; i++) { i8arr[i] = i8arr[i] * i8arr[i]; } Test 3 Title Async (check if this is an asynchronous test) Code var i; for (i = 0; i < N; i++) { ui8arr[i] = ui8arr[i] * ui8arr[i]; } Test 4 Title Async (check if this is an asynchronous test) Code var i; for (i = 0; i < N; i++) { i16arr[i] = i16arr[i] * i16arr[i]; } Test 5 Title Async (check if this is an asynchronous test) Code var i; for (i = 0; i < N; i++) { ui16arr[i] = ui16arr[i] * ui16arr[i]; } Test 6 Title Async (check if this is an asynchronous test) Code var i; for (i = 0; i < N; i++) { i32arr[i] = i32arr[i] * i32arr[i]; } Test 7 Title Async (check if this is an asynchronous test) Code var i; for (i = 0; i < N; i++) { ui32arr[i] = ui32arr[i] * ui32arr[i]; } Test 8 Title Async (check if this is an asynchronous test) Code var i; for (i = 0; i < N; i++) { f32arr[i] = f32arr[i] * f32arr[i]; } Test 9 Title Async (check if this is an asynchronous test) Code var i; for (i = 0; i < N; i++) { f64arr[i] = f64arr[i] * f64arr[i]; }