Bug 133054 (TerrainPerf) - Performance testing, diamond-square terrain generation + canvas
Summary: Performance testing, diamond-square terrain generation + canvas
Status: RESOLVED FIXED
Alias: TerrainPerf
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P5 Enhancement
Assignee: Geoffrey Garen
URL: http://www.playfuljs.com/realistic-te...
Keywords:
Depends on: 133238
Blocks:
  Show dependency treegraph
 
Reported: 2014-05-18 14:14 PDT by Hunter Loftis
Modified: 2014-05-23 15:37 PDT (History)
3 users (show)

See Also:


Attachments
Implementation of diamond-square terrain generation (7.05 KB, text/html)
2014-05-18 14:15 PDT, Hunter Loftis
no flags Details
Patch (9.22 KB, patch)
2014-05-22 11:47 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch (8.67 KB, patch)
2014-05-23 15:00 PDT, Geoffrey Garen
no flags Details | Formatted Diff | Diff
Patch (8.71 KB, patch)
2014-05-23 15:12 PDT, Geoffrey Garen
rniwa: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Hunter Loftis 2014-05-18 14:14:31 PDT
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.
Comment 1 Hunter Loftis 2014-05-18 14:15:11 PDT
Created attachment 231665 [details]
Implementation of diamond-square terrain generation
Comment 2 Geoffrey Garen 2014-05-22 11:47:41 PDT
Created attachment 231901 [details]
Patch
Comment 3 Geoffrey Garen 2014-05-22 11:48:16 PDT
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 4 Ryosuke Niwa 2014-05-22 12:02:34 PDT
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 5 Ryosuke Niwa 2014-05-22 12:03:17 PDT
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 6 Ryosuke Niwa 2014-05-22 12:06:21 PDT
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);
    ...
}})
Comment 7 Geoffrey Garen 2014-05-23 15:00:23 PDT
Created attachment 231994 [details]
Patch
Comment 8 Geoffrey Garen 2014-05-23 15:12:20 PDT
Created attachment 231995 [details]
Patch
Comment 9 Geoffrey Garen 2014-05-23 15:37:55 PDT
Committed r169287: <http://trac.webkit.org/changeset/169287>