Newsgroups: comp.graphics.rendering.raytracing
From: Jon Harrop <use...@jdh30.plus.com>
Date: Tue, 10 May 2005 16:17:23 +0100
Local: Tues 10 May 2005 16:17
Subject: Re: Mini ray tracer
Warp wrote: I agree that the compiler is stupid but I'm comparing g++ as this is a > Jon Harrop <use...@jdh30.plus.com> wrote: >> My post is more about clarity and less about performance. Your proposed >> alterations make the C++ implementation significantly longer and more >> obfuscated and your littering of the source code with "inline" actually >> slows the program down on my Athlon t-bird. > Then your compiler is stupid. Get a better one. common compiler. A better C++ compiler is likely to produce faster code, of course. > And by the way, if you are afraid of "litter" in C++ code, then you Absolutely. :-) > should switch to another programming language. > That "litter", as you call it, is not useless junk as you seem to imply. It also has unexpected platform dependent results, as "tbp" has discovered. > It has a reason and a significance. >> > b) more importantly he's passing large structures by _value_ and i've No, they are small, constant-sized vectors (3D), so pass by value does not >> > turned them into _references_. >> Both implementations use pass by value as this is clearer, shorter and > I hope you are not passing megabyte-sized vectors by value... affect the asymptotic algorithmic complexity. > If your opinion of "clearer" and "shorter" is that the & symbol should Unfortunately, you cannot just use "&" because it will take a reference to a > not be used, then you might want to either check your priorities or > change your programming language (because C++ is not for you). temporary, giving an error like: ray.cpp: In member function `virtual void Sphere::intersect(double&, Vec&, You must either use "const ... &" instead, or make sure that all values are It is precisely this obfuscation (and the fact that these are tiny >> If you want a fair comparison then you should also make equivalent If you completely optimise both implementations then you'll end up with the >> changes to the OCaml implementation. > You want to compare which programming language runs inefficient code same assembler. There is only value in comparing simpler implementations in both languages. So yes, they will not be completely optimised but subjectively "like" real code. >> I chose an inheritance hierarchy because this is the closest C++ I believe I am "really forced to" as virtual lookup is used instead of >> equivalent to a variant type which I see in typical C++ programs. > Inheritance has no overhead in C++. Dynamic binding has. switching on the tag of the variant type/union. In C++, virtual functions are more elegant (and more common in real code) than C-style tagged unions. >> Another optimisation that I made was to replace inheritance with a single Getting rid of inheritance gets rid of the virtual functions. However, it >> Scene struct which represented a group of child scenes or a sphere when >> it had no children. > Inheritance causes no overhead. That kind of optimization is useless. necessarily incurs an equivalent test somewhere else. -- You must Sign in before you can post messages.
To post a message, you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||