I have a simulator that pulls data from a DB - calculates and return JSON result to an ajax call that renders a table for the results.

The calculation procedure are as follow:

  1. grab X number of data that are group together and have weights to them.
  2. use historical data and run a weight distribution algorithm on the group.
  3. return as a JSON the metrics of each data, the old value, and the calculated new value

2 Questions:

1) Is Javascript calculation better or worse (or equal) to PHP calculation in order to yield the results.

2) IF Javascript calculation is faster or on par to PHP then I would assume the trip to call ajax is a small bottleneck. So one possibility would be to pre-load data and have it calculated on the fly. Now how would you persist that pre-loading efficiently? Would that just simply load everything in a simple var via ajax?

Thus far it takes approx 55 seconds for the result to return 2000 entries on 14 days worth of data.

closed as primarily opinion-based by Telastyn, jwenting, GlenH7, amon, Arseni Mourzenko May 3 '14 at 18:24

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Sharing your research helps everyone. Tell us what you've tried and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer. Also see How to Ask – gnat Apr 30 '14 at 16:44
  • What do you mean by Calculation? Can you name the function(s) that you're currently using? – Mahdi Apr 30 '14 at 16:55
  • @mahdi updated. – azngunit81 Apr 30 '14 at 17:23

You are correct you need to optimize your code somehow.

However, the first rule of code optimization is to

Measure, don't guess.

There very likely are performance differences between Javascript on a desktop and PHP on a server, but those differences aren't big enough to solve your problem.

If you are using Chrome as your browser, press F12 and pay attention to the Network section. It also helps to heavily use debugger;, console.time('foo'); and console.timeEnd('foo'); in your javascript code.

Your first question should be to determine if the server is slow in getting the data to the client or if the client is slow in displaying the data.

You can't optimize code until you know for sure which code needs optimizing.

  • yes but the question would be whats the best way to persist in javascript the large data receive in order to be able to measure the performance. – azngunit81 May 1 '14 at 8:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.