wilq said:
Thomas said:
wilq said:
I dont have access to mine profiling function so I create own one
from scratches. Its not great because I do this in hurry, if you have
time to test it - please do. If you have idea on what might
interferee with test cases - i'm open to hear
Cheers:
[...]
(function(){
var times=[];
function addTime()
{
times.push((new Date()).getTime());
Why, +new Date() suffices.
If we use it every time when measuring - it is counted inside measurement
time for both operation (regexp and string)... so what diffrence?
+new Date() is arguably more runtime-efficient than (new Date()).getTime(),
another explicit method call (untested). Historically, type-converting
operations have been more runtime-efficient than type-converting calls.
Yes of course - because of this is an argument that you can change.
The question raised by this is: Is it realistic for an app to perform that
many calls of isMethod() consecutively? If not, the number is too high.
And as it is too high (IMHO), differences in runtime efficiency between
these approaches are in fact not as important as you present them to be.
And, as I said, efficiency is not everything. To begin with, any approach
should balance efficiency against reliability.
You can add those bracers to mine profiling function. As you probably
notice this does not change alot.
Yes, as written in e-mail, with realistic figures the difference is as
negligible as before (in the 50 ms range on a Pentium M 740).
Cheater ? I dont think so - I compare here cases that will occur mostly -
"function" and "object". But I do the same for string solution
No, you don't.
so there is no cheat. In fact its very fair comparsion in mine opinion.
Hardly. Fair would be
someTemp = regExp.test(a) || regExp.test(b);
I open to see a best + worst case as you said that is in string
comparsion.
The problem is that you are picking the cases that are in your favor,
IOW you *are* cheating here.
Yes - this is a idea of this test.
This test is biased(, then).
I propose this test as a answer to post from some time ago that
You were involved in:
Correct me if I'm wrong, you changed:
basically you changed there
(t=='function' || t=='object')
to:
/^(function|object)$/.test(t)
You are wrong. Both about the original and the change.
So here I also did the test. And in post before I explained why this
string comparsion would be better - exacly that if a first boolean
structure will be true, second wont be computed at all. You can try
diffrent cases (both worst, both good) with a="object", b="object" and
a="function", b="function" to see that this is still faster than
regexp...
*Maybe* so, on *your* computer, *without RegExp optimization*. But it is
on *all* computers (running non-obsolete implementations) *less reliable*.
If this is really so big diffrence for you ?
Yes, it is.
Then please consider this for the code that I gave:
var a=typeof (function(){});
var b=typeof ({someObject:0});
I was talking about host objects.
Basically you pointed out some elements in code, but generally that has
nothing to do with really results of test.
Yes, it does. We are not discussing in a theoretical vacuum here.
Efficiency considerations matter because practical issues arise from
following an inefficient approach.
Also you did not provide anything that would show that this approach is
completly wrong. Please then provide code that proves what you saying is
true
I really like seeing things working than only talking. Then I
can judge your solution
I have posted and pointed to the current (abridged) isMethod()
implementation already; now you only need to notice that.
PointedEars