Performance

Jul 18, 2012 at 4:33 PM
Edited Jul 18, 2012 at 4:33 PM

Hi, are there plans to improve performance further?

Another linq js library at 

http://fromjs.codeplex.com/wikipage?title=Performance&referringTitle=Documentation 

From those benchmarks, ling.js 3.0 beta is around 100x slower than no libaray, and around 33x slower than from.js

 

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

//native
var sum=0;
for (var i = 0; i < array.length; ++i) {
            var val=array[i];
            if (val>0){
                sum=sum+val+1;
            }
}

// 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();
Coordinator
Jul 19, 2012 at 1:40 AM

from.js is great library and nice concept.

but is from.js completly lazy?

// from.js freeze
$range(1, 1000000000)
    .where(function (x) { return x % 2 == 0; })
    .select(function (x) { return x + x; })
    .take(10)
    .each(function (x) {
        document.write(x + "<br />");
    });


// linq.js work(0ms)
Enumerable.Range(1, 1000000000)
    .Where(function (x) { return x % 2 == 0; })
    .Select(function (x) { return x + x; })
    .Take(10)
    .ForEach(function (x) {
        document.write(x + "<br />");
    });

 


linq.js's lazy have a complete function and composability.
It is slow instead.

The some optimization is possible, but are hard to be settled fundamentally.
(I still go about the optimization.)

and, the benchmark is a little arbitrary.

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

// 0ms
var first = Enumerable.From(array).First("$ >= 0");
Because from.js and linq.js have optimization for Array.

Coordinator
Jul 19, 2012 at 1:56 AM
Edited Jul 19, 2012 at 2:02 AM

another bench

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

// Google Chrome 20.0.1132.47

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

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

// linq.js ver.3(beta) - took 471ms
var sum = Enumerable.from(array)
    .where("$ >= 0")
    .select("$ + 1")
    .sum();

// IE10(10.0.8250.0 Pre-Release) Private Browse

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

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


// linq.js ver.3(beta) - took 463ms
var sum = Enumerable.from(array)
    .where("$ >= 0")
    .select("$ + 1")
    .sum();


linq.js ver 3.0 speeds up more than ver.2.

In addition, from.js is strong in a browser-dependent aspect ???

Aug 5, 2012 at 4:38 PM

Nice. :)