💾 Archived View for avfig.com › gemlog › raytracing-vs.gmi captured on 2023-05-24 at 17:36:44. Gemini links have been rewritten to link to archived content
⬅️ Previous capture (2022-03-01)
-=-=-=-=-=-=-
By Jeremiah Stoddard on January 9, 2022
I mentioned a couple of posts ago that I worked through the short book "Ray Tracing in One Weekend" and did the exercises in Common Lisp over Christmas weekend. I was pleased with the results, but a little concerned about the performance; I know raytracing doesn't have a reputation for being a speedy process (though I understand that with cutting edge GPU technology, it is starting to make an appearance in the latest games), but I was worried that my code was much slower than it needed to be. Some improvements were made based on a suggestion from a helpful person in #lisp on libera.chat, but a 600x400 pixel image still took well over an hour to generate when performing 100 samples per pixel. I don't like lowering it because the resulting image is not great at 10 samples per pixel.
Last night I decided to install g++ and cmake on my computer in order to compare the speed between my Common Lisp version of "Ray Tracing in One Weekend" and the original C++ version. In order to keep the process within the limits of my patience, I set both versions to generate a 16x9 version of the final scene at 300 pixels wide and 10 samples per pixel. Here are the results for the C++ version, compiled with g++ 10:
$ time ./inOneWeekend >image.ppm Scanlines remaining: 0 Done. real 0m16.873s user 0m16.868s sys 0m0.004s
And for Common Lisp, running in SBCL 2.1.1.debian (straight from the Debian repository):
As can be seen, the C++ version was only about 8 times faster than my Common Lisp version. I am sure an expert Lisper could get better performance, but I really can't complain about the result: It is within an order of magnitude of the language known for speed. Assuming Common Lisp (as used by me) performs this well comparatively in other tasks, it will certainly be sufficient for my needs, and particularly for the small, lightweight games I would like to make.
For anyone interested, my Common Lisp version of the "Ray Tracing in One Weekend" source code is available on Github at: