Simple C and Pascal raytracer benchmark

Produced image

About

This is a pair of benchmarks that implement a very trivial raytracer in C and Pascal - the code is 99.9% the same in both, the main difference is that the C code uses arrays to represent vectors (e.g. float v[3]) whereas the Pascal code uses a Vec record (e.g. var v: Vec) and const/var to pass across functions and procedures (which passes arguments via reference).

Results

I wrote this benchmark mainly because i was interested in doing some retrocoding for old Pentium PCs and wanted to figure out which compiler to choose (most likely VC6 as it is the one that generates the fastest code while creating executables that work on the original Pentium - some old MinGW version might do better, but i do not have any installed). This is the reason for the "pentium", "-5" and "586" references in the table below. But i also decided to try the benchmark in a few other C and Pascal compilers i have installed in my PC.

Here are the results for generating a 640x480 image with 256 rays per pixel (SUBGRID=16) on Windows 10 with an AMD Ryzen 2400G CPU:

Language  Compiler Options Time % Time
C Clang 8.0.0 64bit -Ofast -fno-signed-zeros -fno-trapping-math -funroll-loops -march=native -mtune=native 2.075 100% 
C Clang 8.0.0 64bit -Ofast -fno-signed-zeros -fno-trapping-math -funroll-loops -march=native -mtune=native  2.354 113%
C GCC 8.3.0 64bit -Ofast -fno-signed-zeros -fno-trapping-math -frename-registers -funroll-loops -march=native -mtune=native -fprofile-use 2.377 114%
C GCC 8.3.0 64bit -Ofast -fno-signed-zeros -fno-trapping-math -frename-registers -funroll-loops -march=native -mtune=native 2.721 131%
C GCC 7.4.0 32bit -Ofast -fno-signed-zeros -fno-trapping-math -frename-registers -funroll-loops -march=native -mtune=native 3.444  165%
Pascal Free Pascal 3.0.4 64bit -CfAVX2 -CpCOREAVX2 -O4 3.687 177%
Pascal Free Pascal 3.0.4 64bit -O4 3.875 186%
Pascal Free Pascal 3.0.4 32bit -O4 -CfAVX2 -CpCOREAVX2 4.828 232%
 C GCC 7.4.0 32bit -Ofast -fno-signed-zeros -fno-trapping-math -frename-registers -funroll-loops -march=pentium -mtune=pentium 5.362 258%
C Clang 8.0.0 32bit -Ofast -fno-signed-zeros -fno-trapping-math -funroll-loops -march=pentium -mtune=pentium 6.170 297%
C Visual C++ 6 Release build, __fastcall calling convention, Pentium CPU 6.587 317%
C Visual C++ 6 Release build, __cdecl calling convention, Pentium CPU 6.678 321%
C OpenWatcom 2.0 (nightly) -5r -otexan -ol+ 7.672 369%
C Digital Mars C++ 8.42n -mn -o -5 9.171 441%
Pascal Delphi 2 Optimizations enabled, all runtime checks disabled 9.828 473%
Pascal Free Pascal 3.0.4 -O4 9.953 479%
C Borland C++ 5.2 -4 -O2 10.641 512%
C Borland C++ 5.0 -4 -O2 10.688 515%

Since this was meant for retrocoding on Pentium machines running Windows 95, here are the results for the compilers that generate code working there (percentage time adjusted for the fastest executable in this table):

Language  Compiler Options Time % Time
C Visual C++ 6 Release build, __fastcall calling convention, Pentium CPU 6.587 100%
C Visual C++ 6 Release build, __cdecl calling convention, Pentium CPU 6.678 101%
C OpenWatcom 2.0 (nightly) -5r -otexan -ol+ 7.672 116%
C Digital Mars C++ 8.42n -mn -o -5 9.171 139%
Pascal Delphi 2 Optimizations enabled, all runtime checks disabled 9.828 149%
C Borland C++ 5.2 -4 -O2 10.641 161%
C Borland C++ 5.0 -4 -O2 10.688 162%

FWIW i'd go with Visual C++ 6 for this, but that is because i'll be running it on my main PC. If i was going to code on a real (or emulated) retro computer, i'd use Delphi 2 and just write better code :-P as all C compilers (and especially VC6) are too slow for comfortable use.

Downloads

C source code and Pascal source code (to compile with FPC use -Mdelphi).

There is no license in the code, but if you care consider it under zlib license.