I'm currently creating a calculator for a client that has a set of options which all feed into an algorithm which throws out a few figures. The algorithm is coded in PHP and jQuery feeds in the selected options through it's ajax method.
我正在为一个客户端创建一个计算器,该计算器具有一组选项,这些选项都会输入一个算法,该算法会抛出一些数字。该算法在PHP中编码,jQuery通过它的ajax方法在所选选项中提供。
It's better to show than tell so here it is:
显示比告诉更好,这里是:
http://clients.benpalmer.me/the-eco-experts/solar-calulator/
http://clients.benpalmer.me/the-eco-experts/solar-calulator/
The calculator currently works out the new figures once an option is selected (but not during). Basically, I'm wanting if possible to use real time calculations so when you slide a percentage slider for example - the figures update as you're sliding (not after).
一旦选择了一个选项(但不是在期间),计算器当前会计算出新的数字。基本上,我想要尽可能使用实时计算,所以当你滑动百分比滑块时 - 例如,当你滑动时(而不是之后),数字会更新。
This is set up with a mysql database which has 8760 rows of data and each row is needed to figure the final figures. As you can probably imagine - this isn't particularly fast.
这是使用一个mysql数据库设置的,该数据库有8760行数据,每行都需要计算最终数字。你可以想象 - 这不是特别快。
I'm trying to work out a faster method of figuring this out (I'm not sure if there actually is a faster method).
我正在尝试找出一种更快的方法来解决这个问题(我不确定是否有更快的方法)。
So far I've thought about putting all of this data in to an array instead on the off-chance that it would be faster. After testing this out - it seems to work at the same sort of speed (probably a bit slower). I've also tried to use the SplFixedArray class in PHP but again, with so much data - there is no discernible improvement in performance.
到目前为止,我已经考虑过将所有这些数据放入一个数组中,而不是将它放在更快的可能性上。在测试之后 - 它似乎以相同的速度工作(可能有点慢)。我也尝试在PHP中使用SplFixedArray类,但是再次使用如此多的数据 - 性能没有明显改善。
Unfortunately, I haven't been able to find any other method and I suspect that I'm fighting a losing battle with this one but any suggestions would be greatly appreciated.
不幸的是,我还没有找到任何其他方法,我怀疑我正在与这个方法进行一场失败的战斗,但任何建议都会非常感激。
2 个解决方案
#1
1
You should try Redis(Predis it's the name for PHP library) to store your arrays (basically, relational database is not a good choice here, you should stick with NoSQL engines). I suggest using Hashmaps but please keep in mind that storing more than 1000 keys will slow down the performance of it. A great solution for that problem has been described by Instagram developers on their blog, I think that this might be useful for you in this specific case.
你应该尝试Redis(Predis它是PHP库的名称)来存储你的数组(基本上,关系数据库在这里不是一个好选择,你应该坚持使用NoSQL引擎)。我建议使用Hashmaps,但请记住,存储超过1000个密钥会降低它的性能。 Instagram开发人员在他们的博客上描述了这个问题的一个很好的解决方案,我认为在这个特定情况下这可能对你有用。
#2
0
In the end, I was able to calculate the figures that I needed on the fly with PHP. It involved a HUGE loop but it's helped drastically with the speed.
最后,我能够用PHP计算出我需要的数字。它涉及一个巨大的循环,但它对速度有很大的帮助。
#1
1
You should try Redis(Predis it's the name for PHP library) to store your arrays (basically, relational database is not a good choice here, you should stick with NoSQL engines). I suggest using Hashmaps but please keep in mind that storing more than 1000 keys will slow down the performance of it. A great solution for that problem has been described by Instagram developers on their blog, I think that this might be useful for you in this specific case.
你应该尝试Redis(Predis它是PHP库的名称)来存储你的数组(基本上,关系数据库在这里不是一个好选择,你应该坚持使用NoSQL引擎)。我建议使用Hashmaps,但请记住,存储超过1000个密钥会降低它的性能。 Instagram开发人员在他们的博客上描述了这个问题的一个很好的解决方案,我认为在这个特定情况下这可能对你有用。
#2
0
In the end, I was able to calculate the figures that I needed on the fly with PHP. It involved a HUGE loop but it's helped drastically with the speed.
最后,我能够用PHP计算出我需要的数字。它涉及一个巨大的循环,但它对速度有很大的帮助。