GithubHelp home page GithubHelp logo

kidoman / rays Goto Github PK

View Code? Open in Web Editor NEW
95.0 8.0 23.0 970 KB

Ray tracing based language benchmarks

Home Page: https://kidoman.com/programming/go-getter.html

C++ 15.01% D 11.52% Go 13.23% Java 23.65% Julia 16.93% Nim 9.28% Ruby 10.39%

rays's People

Contributors

jakebolewski avatar kidoman avatar leecbaker avatar m42a avatar onionhammer avatar safety0ff avatar t-mat avatar tkalbitz avatar zaeleus 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  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

rays's Issues

Maintain FOV

Currently, we get different field of view (FOV) image when we set -width and -height. So when increase resolution, almost all rays go straight to sky or ground. And amount of computation is not increase properly.

Following change resolve this problem :

// original
dir := t.Scale(-1)
    .Add(
        a.Scale(rnd(seed) + float64(x))
        .Add(b.Scale(float64(r) + rnd(seed)))
        .Add(c)
        .Scale(16)
    ).Normalize()
// modified
dir := t.Scale(-1)
    .Add(
        a.Scale(rnd(seed) + float64(x*512) / float64(*width))
        .Add(b.Scale(float64(r*512) / float64(*height) + rnd(seed)))
        .Add(c)
        .Scale(16)
    ).Normalize()

This solution make different problem

  • Break compatibility with old benchmarks
  • Break aspect ratio

Go version stack overflows

I haven't investigated this much, but I think the last pass of cleanup seems to have broken the Go version.

Reverting around Line 137 fixes it for me.

Clang compilation for C++

Using Clang from LLVM toolchain may yield different results which should be used instead if it turns out to be faster.

C++ = min( clang , gcc )

A possible optimization for Java (and others)

In the Java code there are a lot of ThreadLocalRandom.current().nextFloat() calls. Random float number generation is quite slow in general. If this is used a lot in the loops it may create a bottleneck.

So Instead, creating a large global random number array beforehand and use the values afterwards would be faster. According to my not-so-reliable test it is around 7-8 times faster than ThreadLocalRandom nextFloat(). Below is an example class for this. Probably using this one instance per thread is a good idea. This can apply to all languages.

Of course this is not exactly random so it may not work at all. But it still may worth a shot when look-up is large enough (hundreds of thousands?).

something like

public class RandomFloatSequence {

    public final int size;
    private float[] data;
    private int sequence; 

    public RandomFloatSequence(int size) {
        this.size = size;
        data = new float[size];
        Random r = new Random();
        for (int i = 0; i < data.length; i++) {
            data[i] = r.nextFloat();
        }
    }

    public float getNext() {
        sequence++;
        if (sequence == size)
            sequence = 0;
        return data[sequence];
    }
}

Confusing about (un)optimization for all langs

(This issue is also related to @tkalbitz's PR #13)

In bc029c5, @kid0m4n has changed lazy computation for bounce. I think this project is not a serious optimization contest, so this change itself is okay.

But should we write more strict code ? I'm confusing about following things:

  • This unoptimization seems opposite to "Why optimize the base algorithm?" section in readme.md
  • This (not) ''making it easy for "not so good" compilers to play catch'' principle leads to further unoptimizations
    • For example: Series of p33 to Math.Pow(p, 99)

Example: Go's case

Old(Lazy) New(bc029c5)
Go 17.93 (100.0%) 18.78 (104.7%)
Go (Math.Pow) 19.83 (110.6%) 21.00 (117.1%)

Way forward

Things to ponder about:

  • Accommodate platforms/runtimes which have a non-insignificant startup time
  • Compare different compilers available for languages like C/C++
  • Publish these results in way so that we can see trends occurring
  • Automated runs?

We need proper pixel conversion

We can see many black dot in highlights. This is caused by overflow. We should implement proper pixel format conversion.

Maybe clamp to [0,255] is enough for this project.

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.