How much each function "costs" to the server

Asked

Viewed 97 times

4

My question is about function is_dir to find out if there is a directory.

How much does it cost for the application to use this function?

How to measure the use of this or another function in PHP?

The function file_exists, for example, they say it costs 12 times more to load a simple application.

  • 1

    I would tell you to measure these values. But sometimes this is not exactly easy to measure or even measurable. I asked a question about how to measure the difference between two fast algorithms in Java. I think in PHP it is less chaotic because (if I’m not mistaken) there is no JIT. If you want to venture and know some limitations of these types of tests, good reading: https://answall.com/q/258476/64969 (PS: the comments on the question are edifying too, it is worth reading them)

  • Measure in programming is always relative, only worth to compare, cite another function you want to compare

1 answer

8


We have no way of knowing.

Time depends on equipment capacity and other configuration factors. This always takes into account the same conditions.

It depends on the conditions you are running at that moment. Things are not as linear as you think.

And it depends on where it is being applied. With different data the time will be different.

Measuring the time of a function is somewhat complicated, especially in a server with load and in web application. What you measure in one situation may not be reproduced in another.

As far as I know PHP even provides suitable tools for measuring well running under these circumstances. You probably have something more advanced, perhaps from a third party that makes it easier to verify.

And will measure for what? It has to have a goal. Knowing the information will do what with it?

The final paragraph says something that doesn’t seem to make much sense, I can’t imagine what the call of this function has to do with the application load and where that number 12 comes from.

  • 4

    Just to complement. If the function was a full black box, you can still tell if it has a measurable time or not. If after collecting a significant amount of data about your cost in time, then you could calculate the average and standard deviation of these data. If the standard deviation is something large, comparable to the obtained values/mean of the data, then you cannot have a good result margin, so your measurement is unable to tell you anything about what was measured. It would be like having an opinion poll with a 40% margin on the result

Browser other questions tagged

You are not signed in. Login or sign up in order to post.