This is an implementation of the diamond-square terrain generation algorithm commonly used to generate fractal-noise worlds in games. It stores height map data in a Float32Array and renders to a fixed-sized canvas. The benchmark averages the result of ten iterations.
Created attachment 231665 [details] Implementation of diamond-square terrain generation
Created attachment 231901 [details] Patch
Thanks, Hunter. I did a bit more formatting to bring this up to WebKit coding standards, and turned it into a patch that can apply to the source tree.
Comment on attachment 231901 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=231901&action=review > PerformanceTests/Canvas/terrain.html:197 > + benchmark(function() { > + var terrain = new Terrain(9); > + terrain.generate(0.5); > + ctx.clearRect(0, 0, width, height); > + terrain.draw(ctx, width, height); > + }); We should use PerfTestRunner.measureTime or reportValueAsync so that perf bots would be able to run this test.
Comment on attachment 231901 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=231901&action=review > PerformanceTests/Canvas/terrain.html:41 > + Math.random = (function() { > + var seed = 49734321; > + return function() { > + /* The Jenkins hash function: > + <http://en.wikipedia.org/wiki/Jenkins_hash_function> > + <http://burtleburtle.net/bob/hash/integer.html> > + */ > + seed = ((seed + 0x7ed55d16) + (seed << 12)) & 0xffffffff; > + seed = ((seed ^ 0xc761c23c) ^ (seed >>> 19)) & 0xffffffff; > + seed = ((seed + 0x165667b1) + (seed << 5)) & 0xffffffff; > + seed = ((seed + 0xd3a2646c) ^ (seed << 9)) & 0xffffffff; > + seed = ((seed + 0xfd7046c5) + (seed << 3)) & 0xffffffff; > + seed = ((seed ^ 0xb55a4f09) ^ (seed >>> 16)) & 0xffffffff; > + return (seed & 0xfffffff) / 0x10000000; > + }; > + })(); This is included in PerformanceTests/resources/runner.js
Comment on attachment 231901 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=231901&action=review >> PerformanceTests/Canvas/terrain.html:197 >> + }); > > We should use PerfTestRunner.measureTime or reportValueAsync so that perf bots would be able to run this test. I think all you need to do is include ../resources/runner.js and then do: PerfTestRunner.measureTime({run: function () { var terrain = new Terrain(9); ... }})
Created attachment 231994 [details] Patch
Created attachment 231995 [details] Patch
Committed r169287: <http://trac.webkit.org/changeset/169287>