Closed megawac closed 9 years ago
Thanks for the PR.
I'll run some benchmarks and merge it in later today.
Here is a benchmark for the browsers : http://jsperf.com/mathp-pr12
I have yet to test in node and io.js, but so far I'm in favor of only merging the rms and euclideanDistanceN.
Waiting for your input.
The changeset of the code here is extremely minimal from a JS engines perspective (pretty much just changing the order of if statements); as such benchmarking this changeset isn't particularly feasible (especially with jsperf) - the actual speed should be ~~ equivalent. See http://mrale.ph/blog/2012/12/15/microbenchmarks-fairy-tale.html if you're interested
The justifcation for this change is more for simplicity/terseness throughout the codebase (I tried to be consistent for each function), leading to more readable code (IMO) and a smaller output size.
On Sun, Mar 8, 2015 at 7:17 AM, Kevin Chapelier notifications@github.com wrote:
Here is a benchmark for the browsers : http://jsperf.com/mathp-pr12
- For Firefox and Safari the only thing to note is that the new euclideanDistanceN is slightly faster.
- The old minkowskiDistanceN performs better on both Chrome and Canary.
- The new euclideanDistanceN performs worse on Chrome but better on Canary.
- The new rms performs better on Canary
- The rest of the performances on Chrome and Canary is slightly skewed toward the old implementations, but it's mostly noise.
I have yet to test in node and io.js, but so far I'm in favor of only merging the rms and euclideanDistanceN.
Waiting for your input.
— Reply to this email directly or view it on GitHub https://github.com/kchapelier/node-mathp/pull/12#issuecomment-77743981.
I'm aware of the issues of the microbenchmarks but it is, afaik, the only tool at our disposal to evaluate the potential performance issues. Obviously, in our case we are mostly measuring how the current JS engines optimize different flavors of the same methods. It is nonetheless an interesting metrics.
As for readability, I'm usually in favor of the "one return statement per function" rule. IMHO it usually makes it easier to reason about and maintain the code, though those advantages are probably be more apparent in more complex codebases.
The decision is ofc up to you, I find the returning immediately with the result is known to be more clear personally (and leads to less nesting). Besides theres multiple returns in several of the other functions already
Merged it all but the minkowskiDistanceN (reverted it to its previous implementation).
The goal of this is to make the loops terser and more consistent in general. I have to go but let me know if you disagree