Google Mail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
Message from discussion Mini ray tracer

View Parsed - Show only message text

Path: g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail
From: tbp...@gmail.com
Newsgroups: comp.graphics.rendering.raytracing
Subject: Re: Mini ray tracer
Date: 9 May 2005 10:51:28 -0700
Organization: http://groups.google.com
Lines: 52
Message-ID: <1115661088.012495.102910@z14g2000cwz.googlegroups.com>
References: <427de4a3$0$39077$ed2e19e4@ptn-nntp-reader04.plus.net>
NNTP-Posting-Host: 193.252.186.162
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1115661094 5237 127.0.0.1 (9 May 2005 17:51:34 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 9 May 2005 17:51:34 +0000 (UTC)
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: z14g2000cwz.googlegroups.com; posting-host=193.252.186.162;
   posting-account=zz-m8w0AAABF9MkKukglSjEQYLZP13TQ

Jon Harrop wrote:
> I then cut this program down to a 66-line OCaml program and ported it
into a
> 97-line C++ program. These programs are compared on this page:
>
>   http://www.ffconsultancy.com/free/ray_tracer/comparison.html
Is that comparison supposed to be fair in any way whatsoever?

Somewhere on an opteron 146 running debian64:
# g++ -g -O3 ray.cpp -o ray
# time ./ray >tt

real    0m13.959s
user    0m13.946s
sys     0m0.009s

# objdump -x ray
[2mn later]
# diff ray_orig.cpp ray.cpp
12,16c12,18
< Vec operator+(Vec a, Vec b) { return Vec(a.x + b.x, a.y + b.y, a.z +
b.z); }
< Vec operator-(Vec a, Vec b) { return Vec(a.x - b.x, a.y - b.y, a.z -
b.z); }
< Vec operator*(double a, Vec b) { return Vec(a * b.x, a * b.y, a *
b.z); }
< double dot(Vec a, Vec b) { return a.x*b.x + a.y*b.y + a.z*b.z; }
< Vec unitise(Vec a) { return (1 / sqrt(dot(a, a))) * a; }
---
>
> inline Vec operator+(const Vec &a, const Vec &b) { return Vec(a.x +
b.x, a.y + b.y, a.z + b.z); }
> inline Vec operator-(const Vec &a, const Vec &b) { return Vec(a.x -
b.x, a.y - b.y, a.z - b.z); }
> inline Vec operator*(const double a, const Vec &b) { return Vec(a *
b.x, a * b.y, a * b.z); }
> inline double dot(const Vec &a, const Vec &b) { return a.x*b.x +
a.y*b.y + a.z*b.z; }
> inline Vec unitise(const Vec &a) { return (1 / sqrt(dot(a, a))) * a;
}
>
# g++ -g -O3 ray.cpp -o ray
# time ./ray >tt

real    0m10.493s
user    0m10.483s
sys     0m0.005s

If your point was to show how to write unbelievably inneficient code in
C++, you've succeeded.
Can't wait for a C++ vs Java comparison.


Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google