php vs javascript speed for processing information
I have a database that contains strings in the format: "key:value|key:value|key:value|key:value"
Due to some other reasons, I can not have the key value pairs stored in the database.
Should I use PHP to split the string and pass it into the javascript charting framework, or,
Should I pass the complete string开发者_如何学Go into javascript and have javascript parse it.In theory, either would be acceptable. In practice, I would lean toward doing as much repetitious work on the server as possible. If you think about it in terms of which can do it faster, you KNOW how fast your server can do it. The resources stay (relatively) constant.
Doing it in javascript relies on the client environment. With a web application, the client environment is infinitely varied. You never know how much memory a client will have available, so it is impossible to estimate how efficiently they can parse the data. 99% of your clients might be fine, but the other 1% get a locked browser when they use your script.
The safest bet is always to use known quantities as much as possible. In this case, the sever is your known quantity - do the work there.
It's more or less negligable. Something to consider, however, is the possible length of the sting. If you know that there will be be quite a bit of NVPs then it might be smart to just transmit as the single string and break it up on the other end (assuming it will have the same glue to attach the parts).
If the string is data specific and the string is generated from the backend, it might be better to let PHP manipulate it. You usually want to limit most of your javascript for UI/client-side interaction, unless of course your using JS on the backend.
精彩评论