Skip to content

nippur72/Dart.RayTracerDemo

Repository files navigation

RayTracerDemo

In this project, the same raytracer program was written in C#, Dart, Java and TypeScript.

Sources were then compiled to JavaScript with their respective compilers and run on all major browsers. They were run also on their respective virtual machines (where available).

The raytracer builds a 3d scene made of 300 reflecting spheres randomly placed on the space over a plane surface.

The time elapsed to render a 640x480 image of the scene was measured and the result is tabled here:

Environment               Elapsed time (secs) 
============================================
Java native JVM on Windows              5,6
Dart VM (unchecked mode) on Dartium     8,3
TypeScript to Javascript on Firefox    12,8
C# to javascript on Firefox            13,5
TypeScript to Javascript on Chrome     13,8
C# to javascript on Chrome             15,0
Java to JavaScript (GWT) on Chrome     16,1
dart2js on Chrome                      17,6
Dart VM (checked mode) on Dartium      25,9
C# native (CLR) on Windows             40,1
Java to JavaScript (GWT) on Explorer   54,1
TypeScript to Javascript on Explorer   56,1
C# to javascript on Explorer           59,9
dart2js on Explorer                   103,3
Java to JavaScript (GWT) on Firefox   176,2
dart2js on Firefox                    196,1

Hardware and Software used for the test:

  • AMD Athlon II X4 640 processor running @3GHZ
  • Windows 7 PC, 64 bits, 8GB Ram
  • Firefox 37.0.1
  • Chrome 41.0
  • Explorer 11.0.96
  • Dart SDK 1.9.1
  • Java 1.8.0_40
  • .NET 4.5.1
  • Saltarelle Compiler 2.6.2
  • TypeScript 1.4

The RayTracer program

The raytracer program used in this test was originally written in C# by IainC in 2009 (license info included in the source) and firstly appeared as a demo for the JSIL compiler.

When I started to play with Dart, I wrote a port for this raytracer in order to compare Dart to C#. Eventually a Java and TypeScript version were added, making this test become a test among the major Web development languages.

Run the test yourself

Here's how to build and run the program by yourself:

C# - Saltarelle compiler

Windows only:

  • open the folder Saltarelle.RaytracerDemo
  • open the .sln file in Visual Studio 2013
  • open nuget console and type update-package, this will download the compiler
  • rebuild the solution
  • open the file index.html inside the WebSite folder with your browser

C# - Native CLR

For Windows:

  • open the folder CSharp.RaytracerDemo
  • open the .sln file in Visual Studio 2013
  • build
  • launch CSharp.RayTracerDemo.exe from bin\Release\ folder
  • click on the button to render the image

C# - Mono virtual machine

  • install Mono (tested with 3.2.3)
  • add Mono-3.2.3\bin to PATH variable
  • from command prompt go to CSharp.RaytracerDemo\CSharp.RaytracerDemo
  • run build_mono.bat
  • launch Mono_RaytracerDemo.exe
  • click on the button to render the image

Dart

All systems, with DartEditor:

  • from DartEditor open the folder Dart.RayTracerDemo
  • from menu 'Pub build' to generate the JavaScript files
  • open the build directory and launch index.html
  • Dart native VM (Dartium) can be run directly from the editor (Manage Launches)

Java GWT

All systems, requires Java and Maven installed:

  • from shell cd to JavaGWT.RaytracerDemo
  • type mvn clean package and wait build to complete
  • open directory javaraytracerdemo-1.0-SNAPSHOT
  • launch with your browser gwt_raytracerdemo.html

Java native

All systems, requires Java and Maven installed:

  • from shell cd to JavaGWT.RaytracerDemo
  • type mvn clean package and wait build to complete
  • type java -cp target/javaraytracerdemo-1.0-SNAPSHOT/WEB-INF/classes io.github.timeu.javagwtraytracerdemo.server.App
  • The image isn't displayed but is calculated in memory.

TypeScript

Windows only:

  • open the folder TypeScript.RaytracerDemo
  • open the .sln file in Visual Studio 2013
  • rebuild the solution
  • open the file index.html inside the WebSite folder with your browser

History

20-Apr-2015 Fixed bug when running in IE

12-Apr-2015 Updated to latest language versions Tests run again on latest browsers

31-Aug-2014: C# native changed "class" to "struct" in Vector3f to take advantage of value types Added build with Mono batch file

30-Aug-2014: Fixed Java native version of MersenneTwister Converted Java native to double to make it comparable with other implementations Converted C# native to double to make it comparable with other implementations Added checksum to the rendered scene to make sure it's pixel-exact correct

29-Aug-2014: Made native C# render on screen instead of memory Fixed native C# random bug, implemented MersenneTwister natively

26-Aug-2014: Added Java GTW and JVM implementation

24-Aug-2014: Added Typescript implementation

23-Aug-2014: Added C# native (CLR) implementation

22-Aug-2014: First release featuring Dart and C#