Skip to content

Commit

Permalink
Benchmark rendering performance
Browse files Browse the repository at this point in the history
  • Loading branch information
rschenk committed Sep 6, 2018
1 parent 3b96d08 commit 3fa4cbf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/image_processor.worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,7 @@ function relax_points_and_send() {
let elapsed_time = time_end - time_start
let interval = Math.max(1, 1000/fps - elapsed_time)
timeout = setTimeout(relax_points_and_send, interval)
} else {
postMessage({ cmd: 'done' })
}
}
14 changes: 13 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { render_tsp } from './tsp.js'

import ImageProcessor from './image_processor.worker.js'

let render_times = []

let url = "/donut.png",
num_points = 2000,
dpr = window.devicePixelRatio || 1,
Expand Down Expand Up @@ -44,14 +46,24 @@ function raster_loaded() {
}

function handle_image_processor_message(e) {
if (e.data.cmd = "points") {
if (e.data.cmd == "points") {
let tstart = new Date(), tend
console.log("[main] Received points from processor")

context.clearRect(0, 0, canvas.width, canvas.height)
context.fillStyle = "#000000"

points = e.data.points
points.map(draw_point)

tend = new Date()

render_times.push( tend - tstart )
} else if (e.data.cmd == "done") {
console.log("[main] Done")
let sum = render_times.reduce(function(a, b) { return a + b; });
let avg = sum / render_times.length;
alert(`[main] Average render time: ${avg}`)
} else {
console.log("[main] received unknown message from processor")
console.log(e)
Expand Down

0 comments on commit 3fa4cbf

Please sign in to comment.