Skip to content

Commit

Permalink
performance edge case. needs to be solved
Browse files Browse the repository at this point in the history
  • Loading branch information
gerich-home committed Mar 24, 2016
1 parent 71813b2 commit ee7a353
Show file tree
Hide file tree
Showing 2 changed files with 113 additions and 0 deletions.
110 changes: 110 additions & 0 deletions performance-tests/scenarios/computedDiamondUpdate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
var Benchmark = require('benchmark');
var itDepends = require('../../out/dist/it-depends.js');
var ko = require('knockout');

module.exports = function(updatesCount, dependenciesCount) {
Benchmark.prototype.args = {
updatesCount: updatesCount,
dependenciesCount: dependenciesCount,
ko: ko,
itDepends: itDepends
};

Benchmark.prototype.setup = function() {
var updatesCount = this.args.updatesCount;
var dependenciesCount = this.args.dependenciesCount;
var ko = this.args.ko;
var itDepends = this.args.itDepends;

var initialValue = -1;

function _noop() {
return function() {};
}

function setupKnockout() {
var x = [];
for (var j = 0; j < dependenciesCount; j++) {
x.push(ko.observable(-1));
}

var a = ko.pureComputed(function() {
var z = 0;
for (var j = 0; j < dependenciesCount; j++) {
z += x[j]();
}
return z;
});

var b = ko.pureComputed(function() {
return a();
});

var c = ko.pureComputed(function() {
return a();
});

var d = ko.observable(initialValue);

var e = ko.pureComputed(function() {
return d() % 2 == 0 ? b() : c();
});

return d;
}

function setupitDepends() {
var x = [];
for (var j = 0; j < dependenciesCount; j++) {
x.push(itDepends.value(-1));
}

var a = itDepends.computed(function() {
var z = 0;
for (var j = 0; j < dependenciesCount; j++) {
z += x[j]();
}
return z;
});

var b = itDepends.computed(function() {
return a();
});

var c = itDepends.computed(function() {
return a();
});

var d = itDepends.value(-1);

var e = itDepends.computed(function() {
return d() % 2 == 0 ? b() : c();
});

var s = e.onChange(function(){

});

return d;
}

var koobservable = setupKnockout();
var idobservable = setupitDepends();
};

var suite = new Benchmark.Suite('computed diamond updated ' + updatesCount + ' times with ' + dependenciesCount + ' hidden dependencies');

suite.add('knockout', function() {
for (var j = 0; j < updatesCount; j++) {
koobservable(j);
}
});

suite.add('itDepends', function() {
for (var j = 0; j < updatesCount; j++) {
idobservable.write(j);
}
});

return suite;
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var computedDiamondUpdate = require('../../scenarios/computedDiamondUpdate');

module.exports = computedDiamondUpdate(1000, 500);

0 comments on commit ee7a353

Please sign in to comment.