javascript - speed of setter functions not what expected -
I am comparing the performance of two different types of sets as shown below:
Var q = {}; Var z = {}; (Function () {var x = 1; q.x = function () {return x;}; q.x.set = function (val) {x = val;};}) (); (Function () {var x = 1; z.x = function () {return x;}; z.x_set = function (val) {x = val;};}) (); The difference is where the setter is stored: q.x.set vs z.x_set . I hope that the z version to run faster because it needs to see a lower table contrast the q version is constantly fast, why any thoughts? Here's a few results:
There are some results from the different browsers of your experiment. Let's take a look at the results.
So we expect to be faster than z to q . But when we examine the results, we see two different categories of results. - The result is a little faster, moving towards almost similar,
q . - OR
z is quite fast. It tells me that it is on the mercy of the implementation of various JS engines. Various JS engines use a ton of low level adaptation, at the time of these very small atomic operations. Change the characteristics of Perhaps the q pattern triggers an optimization that is not in some browsers. Or maybe some browsers have optimization for the z pattern, which does not support older browsers. But given the lack of continuity, it is very difficult to answer why . One thing that clearly makes results, is that is faster than z q . Sometimes q gets faster, but when z gets faster, then it is very fast.
But practically, the difference Is negligible. It is a small operation. Small changes in small operations can take major changes, which are in the perspective of one percent, but in a large application, there are very small changes in performance profiles. Personally, I think this is academically interesting, but there are very few real results.
Comments
Post a Comment