-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
performance edge case. needs to be solved
- Loading branch information
1 parent
71813b2
commit ee7a353
Showing
2 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
3 changes: 3 additions & 0 deletions
3
...mance-tests/tests/computedDiamondUpdates/computedDiamond1000UpdatesWith500Dependencies.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var computedDiamondUpdate = require('../../scenarios/computedDiamondUpdate'); | ||
|
||
module.exports = computedDiamondUpdate(1000, 500); |