Skip to content

abelsson/rays

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rays

Ray tracing based language benchmark inspired from:

Why?

I have written two blog posts describing the intent behind this:

Reddit discussion thread

Why ray tracing?

  • I picked the "Business card raytracer" as it was written in C++ (so a high value fast target) and extremely concise (so I wouldn't be bored to death porting it to Go)

  • The ray tracing algorithm (as implemented) was inherently parallelizable. I wanted to definitely compare and contrast the ease with which I could just take a single threaded solution and have it quickly scale up to multiple cores

  • I was fascinated with the subject of ray tracing since my highschool days. I had coded up a decent raytracer in VB6 (shudder) and even done rudimentary anti-aliasing, etc. The fact that the end result of a benchmark run was a graphic image acted as a self motivator for me

Different Implementations

Currently, the following versions are currently available, and tracked in their own folders:

  • Go (optimized, multi-threaded)
  • C++ (optimized, multi-threaded)
  • Java (optimized, multi-threaded)

Please feel free to implement the benchmark (refer to the original C++ version here) in the language of your choice. All optimizations are welcome but try not to stray away too far from the spirit of the original algorithm. The existing implementations can always act as a litmus test.

Also, optimizations to the existing implementation are obviously welcome. I will regularly update the results based on activity/updates to the code.

Why optimize the base algorithm?

Also, shouldn't we leave it to the compilers to do their best

Optimizing in a particular language also gives you a feel of "how far" you can push the boundaries of performance when the need arises. Micro optimizations are the root of all evil, no doubt; but not when the subject matter is benchmarking itself (plus, it doesn't hurt that it makes the process fun)

Think of this as a great opportunity to learn the various nuances of these languages, which are otherwise extremely hard to learn/master.

How to use

Prerequisite

  • go 1.2rc1 or later
  • gcc 4.8.1 or later
  • Java 7 or later
  • GIMP for opening the rendered images

Go version

  • go get -u github.com/kid0m4n/rays/gorays
  • time gorays > gorays.ppm
  • open gorays.ppm

C++ version

  • git clone git@github.com:kid0m4n/rays.git
  • cd rays
  • c++ -std=c++11 -O3 -Wall -pthread -ffast-math -mtune=native -march=native -o cpprays cpprays/main.cpp
  • time ./cpprays > cpprays.ppm
  • open cpprays.ppm

Java version

  • git clone git@github.com:kid0m4n/rays.git
  • cd rays/javarays
  • javac rays/Raycaster.java
  • time java rays.Raycaster > javarays.ppm
  • open javarays.ppm

Current Performance

The current performance stacks up like so:

512x512 image 2048x2048 image 4096x4096 image

Contributors

The following have contributed to the project one way or the other:

Thanks to everyone for all the help given :)

About

Ray tracing based language benchmarks

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 40.4%
  • C++ 36.4%
  • Go 23.2%