thedo
Posts: 13
Joined: Sun Jan 22, 2012 6:25 pm

Raytracer in C# & F# running on Mono

Tue Jul 03, 2012 6:58 am

https://bitbucket.org/thedo666/raytracer

I decided to port some old code a while back to F#. I then decided to tidy it a little and run it on my Raspberry Pi. I've attempted to make each version as idiomatic to the general language syntax as possible, so there are differences (although the scene rendered at the end is identical)

On my i7 at work it renders the 1280x720 scene in around a second. On my raspberry pi it renders in around 11 minutes :)

Now going to work on a C++11 version for kicks.

Hope someone out there finds this code useful.
csharp.jpg
csharp.jpg (53.77 KiB) Viewed 3270 times

User avatar
SN
Posts: 1012
Joined: Mon Feb 13, 2012 8:06 pm
Location: Romiley, UK
Contact: Website

Re: Raytracer in C# & F# running on Mono

Thu Jul 05, 2012 10:56 am

How does this perform in Mono on the Pi

The fastest coded solution is always going to be C (or C++) but I'm interested to know if some (compiled) C# were run in Mono what kind of comparison could be made (e.g. expect 50% performance as compared to C/C++)
Steve N – binatone mk4->intellivision->zx81->spectrum->cbm64->cpc6128->520stfm->pc->raspi ?

thedo
Posts: 13
Joined: Sun Jan 22, 2012 6:25 pm

Re: Raytracer in C# & F# running on Mono

Thu Jul 05, 2012 11:44 am

"On my i7 at work it renders the 1280x720 scene in around a second. On my raspberry pi it renders in around 11 minutes "

So around 600 times slower than an i7 on .net vs pi on Mono)

Its almost all FP math so i'm guessing that Mono on debian on the pi is using soft fp? That would explain why it is quite so slow. IIRC someone compared the pi CPU to around a 300Mz Intel, so by that reckoning my quad core 3Ghz should only be 40 times faster, so 600 times is an extra scale of 10 out again.

The C++ version is still WIP - my C++ is VERY VERY rusty so has already taken 3 times longer to write than the F# version. And it doesnt work yet! The C# & F# ones are optimized for multicore too, which may actually be a hinderance on the pi.

The source should all be available on BitBucket, so feel free to grab it and have a look - compile & play.

thedo
Posts: 13
Joined: Sun Jan 22, 2012 6:25 pm

Re: Raytracer in C# & F# running on Mono

Sun Jul 15, 2012 5:19 pm

(redface) now the repo is public for anyone to clone.

Will be interested to see if hf enabled raspbian makes a significant difference on Mono as its almost all fp math!

JohnStabler
Posts: 6
Joined: Sat Jun 09, 2012 4:27 pm

Re: Raytracer in C# & F# running on Mono

Tue Jul 17, 2012 8:29 am

thedo wrote:"On my i7 at work it renders the 1280x720 scene in around a second. On my raspberry pi it renders in around 11 minutes "

So around 600 times slower than an i7 on .net vs pi on Mono)

Its almost all FP math so i'm guessing that Mono on debian on the pi is using soft fp?
It would be interesting to see how this performs on the lastest Raspbian build with hard fp support.
John Stabler MBCS - Veteran Computer Programmer

thedo
Posts: 13
Joined: Sun Jan 22, 2012 6:25 pm

Re: Raytracer in C# & F# running on Mono

Wed Jul 18, 2012 1:37 pm

I've installed Raspbian but not mono yet. I'll probably test in next couple of days - Daddy duties come first :)

Will post results here, but feel free to get code and try first :)

thedo
Posts: 13
Joined: Sun Jan 22, 2012 6:25 pm

Re: Raytracer in C# & F# running on Mono

Thu Jul 19, 2012 8:06 pm

Good news: **significantly** faster
Bad news: don't know by how much yet

So if you look on the 1st screenshot you'll seein the top left corner there are some numbers. That's the render time. It worked on Debian Wheezy.

On Raspbian it gets to the rendering text on the Graphics object and barfs. So tomorrow I'll tweak it to log to the command line instead.

So verdict so far on Raspbian Mono - fast but unstable so far.....

thedo
Posts: 13
Joined: Sun Jan 22, 2012 6:25 pm

Re: Raytracer in C# & F# running on Mono

Fri Jul 20, 2012 9:52 pm

Exciting news: F# version - under 5 minutes. That's over twice as fast on Raspbian! The C# version was around the 7 minute mark - so around 33% faster.

Bad news still tho - bitmaps seem totally broken. The saved output is garbage for both versions. Identical garbage but garbage nonetheless. Identical exe runs perfectly (but more slowly) on Debian Wheezy.

amigarulez
Posts: 42
Joined: Wed Jul 18, 2012 10:16 am

Re: Raytracer in C# & F# running on Mono

Fri Jul 20, 2012 9:57 pm

Raspbian has some mono issues.

Read more here:
http://www.raspberrypi.org/phpBB3/viewt ... 66&t=11634

bicarbonato
Posts: 16
Joined: Wed May 23, 2012 2:25 am

Re: Raytracer in C# & F# running on Mono

Wed Aug 22, 2012 10:04 pm

SN wrote:How does this perform in Mono on the Pi

The fastest coded solution is always going to be C (or C++) but I'm interested to know if some (compiled) C# were run in Mono what kind of comparison could be made (e.g. expect 50% performance as compared to C/C++)

Sorry, but i guess the fastest coded solution would be always Fortran. It otimizes better than C, because there is no pointers.

Return to “Other languages”

Who is online

Users browsing this forum: No registered users and 4 guests