简体   繁体   English

浮点运算,C / C ++的方法去哪儿?

[英]Floating Point Arithmetic, C/C++ the way to go?

I'm creating a web application that does some very heavy floating point arithmetic calculations, and lots of them! 我正在创建一个Web应用程序,它执行一些非常繁重的浮点算术计算,其中很多! I've been reading a lot and have read you can make C(and C++) functions and call them from within PHP, I was wondering if I'd notice a speed increase by doing so? 我已经阅读了很多内容并且已经阅读过你可以制作C(和C ++)函数并在PHP中调用它们,我想知道我是否注意到这样做会增加速度?

I would like to do it this way even if it's only a second difference, unless it's actually slower. 我想这样做,即使它只是第二个区别,除非它实际上更慢。

It all depends on the actual number of calculations you are doing. 这一切都取决于您正在进行的实际计算次数。 If you have thousands of calculations to do then certainly it will be worthwhile to write an extension to handle it for you. 如果你有成千上万的计算要做,那么一定要编写一个扩展来为你处理它是值得的。 In particular, if you have a lot of data this is where PHP really fails: it's memory manager can't handle a lot of objects, or large arrays (based on experience working with such data). 特别是,如果你有很多数据,这就是PHP真正失败的地方:它的内存管理器无法处理很多对象或大型数组(基于使用这些数据的经验)。

If the algorithm isn't too difficult you may wish to write it in PHP first anyway. 如果算法不太困难,您可能还是希望先用PHP编写它。 This gives you a good reference speed but more importantly it'll help define exactly what API you need to implement in a module. 这为您提供了良好的参考速度,但更重要的是,它有助于准确定义您需要在模块中实现的API。


Update to "75-100 calculations with 6 numbers". 更新为“使用6个数字进行75-100次计算”。

If you are doing this only once per page load I'd suspect it won't be a significant part of the overall load time (depends what else you do of course). 如果你每页加载只做一次,我怀疑它不会是整个加载时间的重要部分(取决于你当然做了什么)。 If you are calling this function many times then yes, even 75 ops might be slow -- however since you use only 6 variables perhaps their optimizer will do a good job (whereas with 100 variables it's pretty much guaranteed not to). 如果你多次调用这个函数然后是,甚至75个操作可能会很慢 - 但是因为你只使用了6个变量,它们的优化器也可能做得很好(而100个变量则非常保证不会)。

Check SWIG . 检查SWIG

Swig is a way to make php (and other languages) modules from your C sources rather easily. Swig是一种使C语言源中的php(和其他语言)模块非常容易的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM