This project is read-only.

Iterating Speed

// Tested under Chrome

var array = new Array(10000000);

// counting zeros not using LINQ functions - took 6635ms
var count = 0;
for (var i = 0; i < array.length; ++i) {
    if (array[i] == 0) ++count;
}

// using LINQ with functional expressions - took 6235ms
var count = $from(array).count(function(v) {
    return v == 0;
});

// using LINQ with lambda expressions - took 5441ms
var count = $from(array).count("$ == 0");
As you can see, LINQ functions can even work faster than original code written inefficiently.

Functional Expressions vs Lambda Expressions

from.js always try to convert the given lambda expressions into original codes. It can not be done when it is given by functional expressions because of closures. For this reason, lambda expressions work faster than functional expressions in most cases. So it is strongly recommended to use lambda expressions as long as possible.

Comparing with other libraries

All tests were done under Chrome.

Performance Test with linq.js

var array = new Array(1000000);
for (var i = 0; i < array.length; ++i) {
    array[i] = 0;
}

// linq.js - took 2755ms
var sum = Enumerable.From(array)
    .Where("$ >= 0")
    .Select("$ + 1")
    .Sum();

// from.js - took 41ms
var sum = $from(array)
    .where("$ >= 0")
    .select("$ + 1")
    .sum();

Performance Test with JSLINQ

var array = new Array(10000000);
array[0] = 0;

// JSLINQ - took 6722ms (not lazy)
var first = JSLINQ(array).First(function(v) { return v >= 0; });

// from.js - took 0ms (lazy)
var first = $from(array).first("$ >= 0");

Last edited Jun 5, 2012 at 1:12 PM by suckgamoni, version 6

Comments

No comments yet.