Java vs. C ++ - 光线跟踪 [英] Java vs. C++ - Raytracing

查看:160
本文介绍了Java vs. C ++ - 光线跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Java中创建了一个简单的光线追踪器作为一个爱好项目,好吧,它很慢。不是很慢,但仍然缓慢。我不知道我是否可以使用低级语言(如C或C ++)获得任何性能增益,或者差异可以忽略不计,我应该坚持改进我的算法。

I created simple ray tracer in Java as a hobby project, and well, it's slow. Not dramatically slow, but slow nevertheless. I wonder if I can get any performance gain using lower level language like C or C++ or will the difference be negligible and I should stick to improving "my" algorithm?

推荐答案

我认为问题已经回答为YES,不是解释型语言将在99.99%的情况下运行比同一个VM下的同一算法。
这说(在java和c / c ++的图像处理工作很多,其中内存和时间很重要)我想你应该首先尝试优化你的代码,这里是我的建议:

I think the question have been answered as YES a not interpreted language will in 99.99% of the cases run faster than the same algorithm under a VM. This said (having worked a lot in image processing both in java and c/c++ where memory and time mattered) I think you should at first try to optimize your code, here are are my advises:


  • 尝试使用分析器找到代码的瓶颈。我们有时会忽略的很多东西都可以用这样的工具(比如类型转换,不必要的对象创建,最关键的功能,应该首先优化)。分析器必须是你的朋友。

然后(只是几个例子我可以看到光线追踪):

Then (just few examples I could see for raytracing):

  • Replace tan/sin/cos by lookup tables (as long as you can) or approximate functions
  • Try to process data per array and not per sample
  • Try using multiple threads

现在这些东西都是好,但如果速度对你来说非常重要,建议使用ac或c ++语言(即使你可以),但更有可能专注于OpenCL。这可能是最好的工具可用,最适合建设光线跟踪引擎。想象一下,你不是说有30%的改进,但更有可能是10'000%(100x更快)这里是一个java接口: http://jogamp.org/jocl/www/
祝好运: - )

Now those things are "good" but if the speed is really critical for you, I would not suggest to use a c or c++ language (even if you could) but more likely to focus on OpenCL. This is probably the best tool available and most adapted for building ray tracings engine. Just imagine you are not talking there of an improvement of 30% but more likely 10'000% (100x faster) Here is a java interface: http://jogamp.org/jocl/www/ Good luck :-)

这篇关于Java vs. C ++ - 光线跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆