Code Monkey home page Code Monkey logo

raytracer's Introduction

About

Raytracer benchmarks based on Typescript sample.

Results

Language / Compiler Time [ms]
Nim 130 ms
C++ (GCC) 160 ms
Fortran 160 ms
C (GCC) 160 ms
Crystal 190 ms
D (LDC) 210 ms
Rust 220 ms
C (MSVC) 250 ms
C++ (MSVC) 250 ms
VB.NET 360 ms
C# 360 ms
Delphi XE6 390 ms
Odin 450 ms
Go 460 ms
D (DMD) 500 ms
Java 8-14 600 ms
Delphi 2010 (32 bit) 720 ms
Node 15 (JS) 734 ms
Julia 783 ms
Scala 820 ms
Node 15 (TS) 1100 ms
F# 1800 ms
Node 8 1800 ms
PHP (PHP 8.0) 7450 ms
HHVM 11000 ms
PHP (PHP 7.4) 24500 ms
PHP (PHP 7.3) 23500 ms
PHP (PHP 7.0) 25500 ms
Ruby 2.6 37600 ms
Ruby 2.2 47800 ms
Python 3.7 61000 ms
Python 3.5 68000 ms
PHP (PHP 5.6) 83000 ms
Zig ? ms
V ? ms
Swift ? ms
Haskel ? ms
Ada ? ms

Lines of code

Language Loc
Python 275
F# 300
Ruby 351
Julia 360
Nim 379
Typescript 412
C# 426
Swift 450
C++ 461
VB.NET 481
D 490
PHP 491
Go 529
C 560
Fortran 565
Java 569
Delphi 678

Comments:

C - Simple, clean, and fast

C++ - Unlike C, C++ version does bounds checking, otherwise, performances are mostly the same

Nim - Uses Quake square root algorithm

Delphi2010 - Uses old 32 bit compiler

Node/V8 - Node is fast

F# - This should be close to C# and VB.Net, but I don't have much experience with F#

Tested On

Tested on AMD FX-8120 Cpu.

raytracer's People

Contributors

darleybarreto avatar edin avatar elvisoric avatar gabriellasso avatar jzakiya avatar lmiq avatar mgrojo avatar paulsmithkc avatar shirleyquirk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

raytracer's Issues

Add JRuby

It might be nice to include JRuby, since we appear to be faster than all recent CRuby versions.

On my system (using OpenJDK 11):

[] ~/projects/raytracer/ruby $ rvm ruby-2.7.0 do ruby RayTracer.rb 
Completed in 20886.185999999998 ms

[] ~/projects/raytracer/ruby $ rvm ruby-3.0.2 do ruby RayTracer.rb 
Completed in 16813.604000000003 ms

[] ~/projects/raytracer/ruby $ rvm jruby-9.3.0.0 do ruby RayTracer.rb 
Ignoring executable-hooks-1.6.1 because its extensions are not built. Try: gem pristine executable-hooks --version 1.6.1
Ignoring gem-wrappers-1.4.0 because its extensions are not built. Try: gem pristine gem-wrappers --version 1.4.0
Completed in 13248.208 ms

[] ~/projects/raytracer/ruby $ rvm jruby-9.3.0.0 do ruby -Xcompile.invokedynamic RayTracer.rb 
Ignoring executable-hooks-1.6.1 because its extensions are not built. Try: gem pristine executable-hooks --version 1.6.1
Ignoring gem-wrappers-1.4.0 because its extensions are not built. Try: gem pristine gem-wrappers --version 1.4.0
Completed in 7894.947999999999 ms

If this scales the same way on your end it would put the JRuby results somewhere between HHVM and PHP, which I'd like to see. ๐Ÿ˜€

D

Hi! Interesting benchmarks ๐Ÿ‘

But I see you are using some deprecated switches for D.

For example "noboundscheck" should be "boundscheck=off".

You're also using a lot of classes instead of structs (compared to the C++ version). If you don't want (don't have time) to change it to structs, consider adding the final keyword before class to make the comparison a bit fairer (vtable) :)

Thanks!

Add Kotlin

Both Kotlin/JVM and Kotlin/Native would be nice :)

Add results for all languages

These languages don't have results:
Zig
V
Swift
Haskel
Ada

I'm interested in the Ada version. It's easy to test in Ubuntu/Debian. Install packages gprbuild and gnat-12 and run gprbuild -p raytracer.gpr.

Revised Rust version not using function test_ray

In going over the revised Rust version from a couple of days ago, the compiler says test_ray function not used, though the image does not appear affected because of it.

    fn test_ray(&self, ray: &Ray) -> Option<f32>
    {
        let intersect = self.intersections(ray);
        return match intersect {
            Some(result) => Some(result.dist),
            None => None
        }
    }

In the Ruby, Crystal, et al version it was used in

  def addLight(col, light, pos, norm, scene, thing, rd)
    ldis  = Vector.minus(light.pos, pos)
    livec = Vector.norm(ldis)
    neatIsect = self.testRay(Ray.new(pos, livec), scene)
   ...
 end

In Nim as

func getNaturalColor(scene: Scene, sp: SurfaceProperties,
  pos, rd, norm: Vector): Color =
  var rdNorm = rd.norm()
  for light in scene.lights:
    let
      ldis = light.pos - pos
      ldisLen = ldis.len()
      livec = ldis.norm()
      neatIsect = scene.testRay(pos, livec)
      ...

C produces no viewable image, Rust produces a different image from all others.

When I ran the C code version, it produces a bad *.bmp file of 1,000,102 bytes, which doesn't show an image.
Also, while the Rust code produces a viewable image, the image has different shading from all the others.

Here are comparisons with other *.bmp files that produce correct viewable images.

โžœ  raytracer ls -al *bmp
-rw-rw-r-- 1 jzakiya jzakiya 1000054 Apr 10 01:28 cpp-raytracer.bmp
-rw-rw-r-- 1 jzakiya jzakiya 1000102 Apr 10 01:28 c-raytracer.bmp
-rw-rw-r-- 1 jzakiya jzakiya 1000054 Apr 10 01:27 d-raytracer.bmp
-rw-rw-r-- 1 jzakiya jzakiya 1000054 Mar 25 11:59 julia-ray.bmp
-rw-rw-r-- 1 jzakiya jzakiya 1000054 Mar 24 17:04 nim-raytracer.bmp
-rw-rw-r-- 1 jzakiya jzakiya 1000054 Apr 10 01:28 nim-RayTracer.bmp
-rw-rw-r-- 1 jzakiya jzakiya  750054 Mar 15 12:43 ruby-raytracer-266.bmp
-rw-rw-r-- 1 jzakiya jzakiya  750054 Mar 15 12:35 ruby-raytracer-272.bmp
-rw-rw-r-- 1 jzakiya jzakiya  750054 Mar 15 12:51 ruby-raytracer-jruby9.2.16.0.bmp
-rw-rw-r-- 1 jzakiya jzakiya  750054 Mar 24 16:54 rust-raytracer.bmp

Fortran version won't build

I'm trying to build the Fortran version and have run into some problems.

raytracer> gfortran --version
GNU Fortran (PCLinuxOS 10.3.0-1pclos2021) 10.3.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

When I use the build instructions I get this error.

raytracer> gfortran.exe main.f95 -O3 -o FRay.exe
zsh: command not found: gfortran.exe

When I ran it without the .exe it gives a missing library error.

raytracer> gfortran main.f95 -O3 -o FRay.exe 
/usr/bin/ld: cannot find -lquadmath
collect2: error: ld returned 1 exit status

Update LOC for versions

Thank you for updating some of the timings.

When you have time, can you also update the LOCs too.

Python is unfarily short because it uses PIL library.

Python appears to be the only language to use external library PIL to write the bitmap out. This makes it significantly shorter then other languages.

I think to be fair to other languages in the lines of code benchmark Python should not use PIL and write the .bmp like the other languages.

Nim's implantation has double empty lines and comments other languages do not have. If Python is forced to write out the bitmap and Nim's code is cleaned up I think Nim might be able to take the top spot in both speed and shortness.

Upgrading Ruby version

I see a number of the language versions have been upgraded.
I've done an optimized version of the original Ruby implementation that mimics Crystal.
How should I submit the new Ruby code to you?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.