Created
July 27, 2011 03:18
-
-
Save solmsted/1108590 to your computer and use it in GitHub Desktop.
My first test with Fabric Engine
This file contains hidden or 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
<!DOCTYPE html> | |
<html dir="ltr" lang="en"> | |
<head> | |
<meta charset="utf-8" /> | |
<meta http-equiv="X-UA-Compatible" content="chrome=1" /> | |
<script id="yui_seed_file" src="http://yui.yahooapis.com/3.3.0/build/yui/yui-min.js"></script> | |
<script src="/Fabric/Core/FABRIC.Wrappers.js"></script> | |
<script src="/Fabric/Core/FABRIC.js"></script> | |
<script src="fabricTest0.js"></script> | |
<title> | |
Test | |
</title> | |
</head> | |
<body class="yui3-skin-sam"> | |
</body> | |
</html> |
This file contains hidden or 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
YUI().use('cssbase', 'cssfonts', 'cssgrids', 'cssreset', 'dump', 'event', 'node', function (Y) { | |
'use strict'; | |
var _fabric = FABRIC.createContext(), | |
_dg = _fabric.DG; | |
Y.on('domready', function () { | |
var array = [], | |
bindingArray, | |
bindingSlices, | |
bodyNode = Y.one('body'), | |
i, | |
length = 10000, | |
newArray = [], | |
nodeArray, | |
nodeSlices, | |
operatorArray, | |
operatorSlices, | |
timer; | |
bodyNode.append('<h3>Array Test: ' + length + ' items<h3>'); | |
for (i = 0; i < length; i += 1) { | |
array[i] = i; | |
} | |
nodeSlices = _dg.createNode('nodeSlices'); | |
nodeSlices.addMember('a', 'Scalar'); | |
nodeSlices.setCount(length); | |
nodeSlices.setBulkData({ | |
a: array | |
}); | |
operatorSlices = _dg.createOperator('operatorSlices'); | |
operatorSlices.setEntryFunctionName('plusSlices'); | |
operatorSlices.setSourceCode([ | |
'operator plusSlices(io Scalar a) {', | |
' a += a;', | |
'}' | |
].join('\n')); | |
bindingSlices = _dg.createBinding(); | |
bindingSlices.setOperator(operatorSlices); | |
bindingSlices.setParameterLayout([ | |
'self.a' | |
]); | |
nodeSlices.bindings.append(bindingSlices); | |
timer = Y.Lang.now(); | |
nodeSlices.evaluate(); | |
newArray = nodeSlices.getBulkData().a; | |
timer = Y.Lang.now() - timer; | |
// Display timer and output some data to make sure the operation worked correctly | |
bodyNode.append('<p>Fabric Slices: ' + timer + ' milis - ' + array[50] + ' - ' + newArray[50] + '</p>'); | |
newArray = []; | |
nodeArray = _dg.createNode('nodeArray'); | |
nodeArray.addMember('a', 'Scalar[]'); | |
nodeArray.setData('a', 0, array); | |
operatorArray = _dg.createOperator('operatorArray'); | |
operatorArray.setEntryFunctionName('plusArray'); | |
operatorArray.setSourceCode([ | |
'operator plusArray(io Scalar a[]) {', | |
' for (Size i = 0; i < a.size; i++) {', | |
' a[i] += a[i];', | |
' }', | |
'}' | |
].join('\n')); | |
bindingArray = _dg.createBinding(); | |
bindingArray.setOperator(operatorArray); | |
bindingArray.setParameterLayout([ | |
'self.a' | |
]); | |
nodeArray.bindings.append(bindingArray); | |
timer = Y.Lang.now(); | |
nodeArray.evaluate(); | |
newArray = nodeArray.getData('a', 0); | |
timer = Y.Lang.now() - timer; | |
// Display timer and output some data to make sure the operation worked correctly | |
bodyNode.append('<p>Fabric Array: ' + timer + ' milis - ' + array[50] + ' - ' + newArray[50] + '</p>'); | |
newArray = []; | |
timer = Y.Lang.now(); | |
Y.each(array, function (a, i) { | |
newArray[i] = a + a; | |
}); | |
timer = Y.Lang.now() - timer; | |
// Display timer and output some data to make sure the operation worked correctly | |
bodyNode.append('<p>Y.each: ' + timer + ' milis - ' + array[50] + ' - ' + newArray[50] + '</p>'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment