tl;dr: Long
rant gloat about how I "win", when really it's only for Chrome that I "win", but a good start nevertheless, and that I really do think Alpha has chance of blowing us all away.
Actually, I'm faster than a for loop sometimes. It technically shouldn't be possible, but I did a test and these two perform the same, and in fact the top one performs better on average
(I think it knows 'noop' does nothing, and between Lazy and my library it may know that too):
for (var i = 0; i < array.length; ++i) {
var result = add1(array[i]);
if (even(result)) noop(add1(result));
}
VS:
for (var i = 0, l = array.length; i < l; ++i) {
var result = array[i] + 1;
if (result % 2 == 0) result += 1;
}
It seems counter-intuitive that the top one is faster since it must make calls, so this tells me that Chrome must be smart enough to inline functions anyways. which means Alpha's solution is happening for my code behind-the scenes
anyways since my code most commonly resembles the first for loop.
So, therefore I might indeed have the absolute maximum in performance in my link library. I don't want to sound like a dick by saying that since I *know* Lazy tried hard and is far more flexible than my library. But
if you want to see how one produces
the fastest "querying library" this is it. This is the best... Otherwise you're just contending with raw for loop speed. If...
if you can go faster than that, then you've succeeded in doing the impossible.
Closed the book, end of the road. Right here... For chrome. But, use Lazy if you want flexibility since this library has none of that. I can only see speed-critical, maximum performing code that consequently needs an upgrade to maintainability to ever use my library... And only there I can see a future for it. Sounds a lot like gaming, too.
Of course, that is if you use Chrome. In FF and IE the experience is, fatser, but not as. And probably more noticeable in Sphere (might even be slower). It's one crutch is function calls. That's all... and Chome happens to have a good, fast solution for that, which my library leverages by incident.
So I digress, it
might be possible to create a library good on all browsers, and in that case Alpha may have the right idea of generating the code for a for loop... Provided the construction itself is fast,
and the generated code turns on any optimizations which I think doesn't.
And is accepted in immature environments like IE. But it is really a promising lead in the best performance for such libraries.
Alpha: you've been quiet, I'm hoping you made some headway. And although I said yours sounds like cheating, well, technically
I am. I'm interested in how your library performs outside of Chrome.