-
hmmm... does this work? maybe more efficient than c/c (as if it mattered!)
if (c-c!=0)
EDIT: no, silly me, as soon as the / or - operator sees it's dealing with a non-numeric string, it will return undefined. It won't actually do any division or subtraction. So same efficiency.
EDIT2: or
if (c*0!=0)
Or, could do:
if (isNaN(parseInt(c)))
-
Code:
100000 Dividing Comparisons Avg: 0.0464 s
100000 Subtracting Comparisons Avg: 0.0457 s
---
100000 Dividing Comparisons Avg: 0.0449 s
100000 Subtracting Comparisons Avg: 0.0463 s
---
100000 Dividing Comparisons Avg: 0.0527 s
100000 Subtracting Comparisons Avg: 0.046 s
---
100000 Dividing Comparisons Avg: 0.0525 s
100000 Subtracting Comparisons Avg: 0.0455 s
---
100000 Dividing Comparisons Avg: 0.0456 s
100000 Subtracting Comparisons Avg: 0.0465 s
---
100000 Dividing Comparisons Avg: 0.0454 s
100000 Subtracting Comparisons Avg: 0.0452 s
---
100000 Dividing Comparisons Avg: 0.0464 s
100000 Subtracting Comparisons Avg: 0.0457 s
---
100000 Dividing Comparisons Avg: 0.045 s
100000 Subtracting Comparisons Avg: 0.0467 s
---
100000 Dividing Comparisons Avg: 0.0462 s
100000 Subtracting Comparisons Avg: 0.0464 s
---
100000 Dividing Comparisons Avg: 0.0451 s
100000 Subtracting Comparisons Avg: 0.046 s
Grand Totals:
PHP Code:
1 Million Dividing Comparisons Avg: 0.04702 s
1 Million Subtracting Comparisons Avg: 0.04618 s
Looks like dividing is actually faster, but, probably negligible. :)
-
That's the way, do the experiment!
But I bet the variation in times is mostly due to Flash noise... over 10 trials, a difference of (0.04702-0.04618) /( (0.04702+0.04618)/2 ) * 100 is only 1.8%... and given the wideness of the variation in the 10 trials (0.0449 - 0.0527 sec for dividing - almost 16%), I'd guess this isn't significant.
If you run it again, I wonder if the overall averages will differ markedly?
100 trials (or 1000) would smooth out this particular source of randomness. hehehe but I really prefer my computational machinery to be deterministic!
PS: I used google to calc the %. convenient
-
if (c>-1)
Code:
check("a");
check("0");
check("9");
function check(c) {
trace(c)
trace(c>-1)
if (c>-1) trace("digit")
else trace("not a digit");
trace("")
}
EDIT1: and I realize now that of course c/c or c-c will do some calculation - when c is numeric.