Benchmark.js
HTML
<script src="https://cdnjs.cloudflare.com/ajax/libs/benchmark/1.0.0/benchmark.min.js"></script>
JavaScript
function test1() {
const width = 2592 * 2
const height = 1944 * 2
const delta = 11
const array = new Uint8Array(width * height)
const out = new Uint8Array(width * height)
for (let y = 0; y < height; y++) {
let current = 0
for (let x = delta; x < width; x++) {
out[y * height + x] = current
current -= array[y * height + x - delta]
current += array[y * height + x]
}
}
}
function test2() {
const width = 2592 * 2
const height = 1944 * 2
const delta = 11
const array = new Uint8Array(width * height)
const out = new Uint8Array(width * height)
for (let y = 0; y < height; y++) {
let current = 0
let idx = y * height + delta
for (let x = delta; x < width; x++) {
out[idx] = current
current -= array[idx - delta]
current += array[idx]
idx++
}
}
}
function test3() {
const width = 2592 * 2
const height = 1944 * 2
const delta = 11
const array = new Uint8Array(width * height)
const out = new Uint8Array(width * height)
for (let y = 0; y < height; y++) {
let current = 0
let idx = y * height + delta
for (let x = delta; x < width; x += 4) {
out[idx] = current
current -= array[idx - delta]
current += array[idx]
idx++
out[idx] = current
current -= array[idx - delta]
current += array[idx]
idx++
out[idx] = current
current -= array[idx - delta]
current += array[idx]
idx++
out[idx] = current
current -= array[idx - delta]
current += array[idx]
idx++
}
}
}
function test4() {
const width = 2592 * 2
const height = 1944 * 2
const delta = 11
const array = new Uint8Array(width * height)
const out = new Uint8Array(width * height)
...