Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #8 from sethladd/master
Browse files Browse the repository at this point in the history
Run benchmarks in browser
  • Loading branch information
johnmccutchan committed May 5, 2013
2 parents 8283bfa + 3a78dfb commit 1b2d13c
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 18 deletions.
29 changes: 29 additions & 0 deletions example/Tracer/dart/app.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
library ray_trace;

import 'dart:html';
import 'dart:math';

part 'color.dart';
part 'engine.dart';
part 'materials.dart';
part 'scene.dart';
part 'shapes.dart';
part 'vector.dart';
part 'renderscene.dart';

// used to check if raytrace was correct (used by benchmarks)
var checkNumber;

main() {
var button = query('#render');
var canvas = query('#canvas');
var time = query('#time');
button.onClick.listen((e) {
canvas.width = int.parse(query('#imageWidth').value);
canvas.height = int.parse(query('#imageHeight').value);
var sw = new Stopwatch()..start();
renderScene(e);
sw.stop();
time.text = sw.elapsedMilliseconds.toString();
});
}
40 changes: 40 additions & 0 deletions example/Tracer/dart/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>

<html>
<head>
<title>index</title>
</head>

<body>
<canvas id="canvas" width="100" height="100" style="border:1px solid black"></canvas>

<div>
Width: <input type="text" id="imageWidth" value="100">
</div>
<div>
Height: <input type="text" id="imageHeight" value="100">
</div>
<div>
Pixel Size: <input type="text" id="pixelSize" value="5,5">
</div>
<div>
Diffuse: <input type="checkbox" id="renderDiffuse" checked>
</div>
<div>
Shadows: <input type="checkbox" id="renderShadows" checked>
</div>
<div>
Highlights: <input type="checkbox" id="renderHighlights" checked>
</div>
<div>
Reflections: <input type="checkbox" id="renderReflections" checked>
</div>
<button id="render">Render</button>
<div>
Time (ms): <span id="time"></span>
</div>
<script type="application/dart" src="app.dart"></script>
<!-- for this next line to work, your pubspec.yaml file must have a dependency on 'browser' -->
<script src="packages/browser/dart.js"></script>
</body>
</html>
1 change: 1 addition & 0 deletions example/Tracer/dart/renderscene.dart
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void renderScene(event) {
renderDiffuse: renderDiffuse,
renderShadows: renderShadows,
renderReflections: renderReflections,
renderHighlights: renderHighlights,
rayDepth: rayDepth
);

Expand Down
47 changes: 31 additions & 16 deletions example/Tracer/js/Tracer.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ Flog.RayTracer.Engine.prototype = {
this.setPixel(x, y, color);
}
}
if (checkNumber !== 2321) {
if (canvas == null && checkNumber !== 2321) {
throw new Error("Scene rendered incorrectly");
}
},
Expand Down Expand Up @@ -702,8 +702,8 @@ Flog.RayTracer.Engine.prototype = {
}
};


function renderScene(){
// 'event' null means that we are benchmarking
function renderScene(event){
var scene = new Flog.RayTracer.Scene();

scene.camera = new Flog.RayTracer.Camera(
Expand Down Expand Up @@ -771,22 +771,39 @@ function renderScene(){

scene.lights.push(light);
scene.lights.push(light1);

var imageWidth = 100; // $F('imageWidth');
var imageHeight = 100; // $F('imageHeight');
var pixelSize = "5,5".split(','); // $F('pixelSize').split(',');
var renderDiffuse = true; // $F('renderDiffuse');
var renderShadows = true; // $F('renderShadows');
var renderHighlights = true; // $F('renderHighlights');
var renderReflections = true; // $F('renderReflections');

var imageWidth, imageHeight, pixelSize;
var renderDiffuse, renderShadows, renderHighlights, renderReflections;
var canvas;

if (typeof(event) == 'undefined' || event == null) {
imageWidth = 100;
imageHeight = 100;
pixelSize = "5,5".split(',');
renderDiffuse = true;
renderShadows = true;
renderHighlights = true;
renderReflections = true;
canvas = null;
} else {
imageWidth = parseInt(document.getElementById('imageWidth').value);
imageHeight = parseInt(document.getElementById('imageHeight').value);
pixelSize = document.getElementById('pixelSize').value.split(',');
renderDiffuse = document.getElementById('renderDiffuse').checked;
renderShadows = document.getElementById('renderShadows').checked;
renderHighlights = document.getElementById('renderHighlights').checked;
renderReflections = document.getElementById('renderReflections').checked;
canvas = document.getElementById("canvas");
}

var rayDepth = 2;//$F('rayDepth');

var raytracer = new Flog.RayTracer.Engine(
{
canvasWidth: imageWidth,
canvasHeight: imageHeight,
pixelWidth: pixelSize[0],
pixelHeight: pixelSize[1],
pixelWidth: parseInt(pixelSize[0]),
pixelHeight: parseInt(pixelSize[1]),
"renderDiffuse": renderDiffuse,
"renderHighlights": renderHighlights,
"renderShadows": renderShadows,
Expand All @@ -795,7 +812,5 @@ function renderScene(){
}
);

raytracer.renderScene(scene, null, 0);
raytracer.renderScene(scene, canvas, 0);
}

Benchmark.report("Tracer", renderScene, renderScene);
12 changes: 12 additions & 0 deletions example/Tracer/js/app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var button = document.getElementById('render');
var canvas = document.getElementById('canvas');
var time = document.getElementById('time');

button.addEventListener('click', function (e) {
canvas.width = parseInt(document.getElementById('imageWidth').value);
canvas.height = parseInt(document.getElementById('imageHeight').value);
var start = new Date();
renderScene(e);
var stop = new Date();
time.innerHTML = (stop - start).toString();
});
1 change: 1 addition & 0 deletions example/Tracer/js/benchmark_tracer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Benchmark.report("Tracer", renderScene, renderScene);
39 changes: 39 additions & 0 deletions example/Tracer/js/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>

<html>
<head>
<title>index</title>
</head>

<body>
<canvas id="canvas" width="100" height="100" style="border:1px solid black"></canvas>

<div>
Width: <input type="text" id="imageWidth" value="100">
</div>
<div>
Height: <input type="text" id="imageHeight" value="100">
</div>
<div>
Pixel Size: <input type="text" id="pixelSize" value="5,5">
</div>
<div>
Diffuse: <input type="checkbox" id="renderDiffuse" checked>
</div>
<div>
Shadows: <input type="checkbox" id="renderShadows" checked>
</div>
<div>
Highlights: <input type="checkbox" id="renderHighlights" checked>
</div>
<div>
Reflections: <input type="checkbox" id="renderReflections" checked>
</div>
<button id="render">Render</button>
<div>
Time (ms): <span id="time"></span>
</div>
<script src="Tracer.js"></script>
<script src="app.js"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion example/Tracer/js/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# d8 is a tool included with V8:
# https://code.google.com/p/v8/

d8 bench.js Tracer.js
d8 bench.js Tracer.js benchmark_tracer.js
4 changes: 3 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
name: benchmark_harness
version: 1.0.2
description: The official Dart project benchmark harness.
author: Dart Project <[email protected]>
description: The official Dart project benchmark harness.
homepage: http://www.dartlang.org
dependencies:
browser: any

0 comments on commit 1b2d13c

Please sign in to comment.